Questions tagged [for]
A tag to denote any questions relating to for loops
460 questions
0
votes
1
answer
63
views
How to batch compress pdfs?
I'm looking to batch compress some pdfs, using the convert to/from ps trick outlined elsewhere. I have a function defined in an .zshrc file:
function pdfcompress() {
for f in "$1"; do
...
0
votes
1
answer
25
views
terraform resource dependency with count(loop)
I'm trying to create stack of multiple vms on KVM_HOST with terraform. The catch is, I'm using pxeboot & kickstart to do installation. Kickstart file needs to carry some dynamic information, like ...
2
votes
1
answer
163
views
Not working break in for loop in bash script for mounting a VHD
I'm not an experienced programmer. So maybe it's obvious for you why the break command in this script does not terminate the loop, but I can't see what is causing the problem. I want to use the script ...
0
votes
1
answer
58
views
using a variable which has content separated by spaces in shell in a for loop
I am trying to read a variable with spaces on prompt and trying to use in a for loop.,
For example:
Enter the items to read separated by space...
apple orange kiwi
read items
for i in "$...
-1
votes
1
answer
65
views
Output of loop variable shows different value than expected
Imagine I have two folders in my current working directory: back/ and front/. I am trying to enter inside each of them and do some stuff. From the simple script below:
for dir in */ ; do
echo &...
-3
votes
4
answers
167
views
How to catch all lines of a repeating pattern and do some actions with the subresults
I am looking for a possibility to catch in a repeating text pattern all variable amount of lines between them and then do an action with it in bash.
Example text:
Total:
text1
text2
Total:
text3
Total:...
4
votes
2
answers
445
views
SSH for loop: parameter passed to function captured in variable is not expanded
I have several servers which have several files with deploy date info I need to parse, and get a local copy of the files which are 2 months old or older.
#!/bin/bash
# split on new line not space
# ...
0
votes
2
answers
251
views
How to run for loop over SSH on remote so that variables expand?
If I ls files without a for loop in a remote host everything is fine however, if I capture the ls in a variable and try to echo each file it fails as the variables don't expand/have a value.
What I ...
3
votes
2
answers
2k
views
How to extract and delete contents of a zip archive simultaneously?
I want to download and extract a large zip archive (>180 GB) containing multiple small files of a single file format onto an SSD, but I don't have enough storage for both the zip archive and the ...
0
votes
2
answers
280
views
Pass multiple arguments from single line from a text file to teminal
I have a python program that requires 2 arguments input-file and output-file.
It reads input-file and creates a copy of that file with some modifications in the output-file.
I created a text file with ...
1
vote
2
answers
2k
views
Is there a syntax for a "for" loop over words or lines in a variable, that will work unmofdified in both bourne shell and zsh?
I have a variable that contains a list of strings, one per line, to be looped over in a for...in...do...done command.
I move regularly between bourne shell and zsh. As far as I can understand it, zsh ...
0
votes
1
answer
850
views
Recursively fix corrupted video files with ffmpeg
I think I'm pretty close to having a code which will start at a directory, then spit out a fixed copy, using fd (instead of find) and ffmpeg. I have written the if statement here as psudo-code:
for i ...
0
votes
3
answers
712
views
for loop through multiple directories and multiple files
I want to check if each .bam file is accompanied with a .bai file. So if clean_xyz_1.sorted.bam is present clean_xyx_1.sorted.bam.bai should also be present. Each file has a variable string in the ...
0
votes
2
answers
127
views
For loop with Multiple IF condition's in Shell scripting
Firstly , In the /tmp/test file path I have the below directories
amb
bmb
cmb
By running the find command, I am getting the below list of files inside these three directories:
amb/eng/canon.amb
bmb/...
1
vote
0
answers
32
views
Do I have to write a shell script purely to access bash for loops inside of say watch? [duplicate]
I'd like to monitor apps that have inotify instance in real-time with watch using something similar to:
watch "for foo in /proc/*/fd/*; do readlink -f $foo; done | grep inotify | sort | uniq -c | ...