The tag has no wiki summary.

learn more… | top users | synonyms

1
vote
3answers
121 views

for loop for running a command for all files in a folder

Suppose I have a folder which contains a lot of audio files. How can I write a for loop so that for each file audioname.mp3 in the folder, these commads are run: convert -size 300x200 xc:lightblue ...
3
votes
4answers
191 views

what is the difference between `find .` and /home/user/* as an input to for command

What is the difference between find . and /home/user/* as an input to for command.? For example: for var in $(find .) do echo "$var" done or for var in /home/user/* do echo "$var" done In the ...
2
votes
2answers
34 views

for loop to iterate through some file nth position

How do I iterate for nth file in a for loop in unix? below some code I have tried but not succeeded #!/bin/bash # n=2 array=( "CTL_MLPOSDTLP1_1.ctl" "CTL_MLPOSDTLP1_2.ctl" "CTL_MLPOSDTLP1_3.ctl" ) ...
3
votes
2answers
69 views

How do I perform the same set of commands within multiple subdirectories, in a numerical order?

Within my parent_directory, I have subdirectories labeled E-11_G, and E-10_G. Within each of those subdirectories, I have more subdirectories labeled E-2_U, E-1_U, and E0_U. In each of those folders, ...
1
vote
2answers
92 views

Parse two files input in for/while loop

I have two files with two different values. I want to run a command in loop which needs input from both file. Let me give the example to make it simple. File1 contents: google yahoo File2 ...
1
vote
0answers
41 views

passing variable through cat EOF command with for loop

How do I get the script run with the sbatch command to run with the 23 individual run_prep_chem_$dd.sh (i.e. run_prep_chem_08.sh...run_prep_chem_30.sh)? I am thinking since its in this for loop that ...
0
votes
1answer
68 views

reading file using for, while - behavior

Consider the below scenario 2 vms - 192.168.229.131, 192.168.229.132 Both the vms has it's ip as 192.168.229.151 & 192.168.229.152 in it's /etc/hosts file Say there are around 50 vms like i ...
0
votes
2answers
121 views

proper way to iterate through contents in a directory [duplicate]

I need to iterate through every file inside a directory. One common way I saw was using the for loop that begins with for file in *; do. However, I realized that it does not include hidden files ...
0
votes
2answers
61 views

Find and for loop

Trying to do a mass convert from M4A to OGG in a large music collection, I have: #!/bin/sh for i in `find /home/family/Music -name *.m4a -print0` #do ffmpeg -i "$i" -acodec libvorbis -aq 6 -vn -ac ...
3
votes
2answers
109 views

Loop in WildCard as Input of Script

I want to use my script on many files sometimes. I used this for the purpose: for etminput in $1 do #process done But this just gives the first input. How can I do the process on every ...
1
vote
2answers
64 views

awk: for-loop with break option

I am trying to use awk to manipulate data.I have a data file with two columns and I would like to find the row that contains an specific value. But there is more than one row that contains this value ...
1
vote
1answer
38 views

accessing substrings from lines in a text file and storing them

I have a text file like this chr1:16840617-16840780 RNU1-1 (2 columns are tab separated) chr3:142139047-142139211 RNU1-100P ............ ............ I want to loop over the lines ...
2
votes
1answer
42 views

reset for loop counter

Simple question: if I have a for loop (zsh) over an unreliable list, by which I mean the list contains entries that can't be predicted beforehand, then can I reset the for loop counter? This ...
2
votes
1answer
1k views

Attach files for sending mail which are the result set of find command

By using find command I got multiple files. Now I want to add all these files as mail attachment. Please help me how to add these files as attachment in single mail. I want to implement this in ...
3
votes
1answer
286 views

Why does this command to copy files in a for loop work in bash but not in zsh?

I'm trying to copy a bunch of files with the same name, but in different subdirectories, to a single directory, changing the names to ones based on the paths to the original files. I use a for loop ...
3
votes
6answers
1k views

Remove last comma from a bash for loop generated string

I am dealing with a situation where I need to create a comma separated list from an array into a heredoc and remove the last comma. I am using bash for piped into sed which is erasing all commas ...
4
votes
3answers
3k views

For loop in Unix : including files from sub directories [duplicate]

A simple for loop in Unix would be: for FILE in $BASE_WORK_DIR/*.pdf do echo $FILE done This will echo all .pdf files inside BASE_WORK_DIR directory. What if BASE_WORK_DIR contains sub ...
4
votes
4answers
277 views

Continue for loop by keyboard

I have user account on a linux machine which I do not know its exact IP address. But I know a range which it is ran on one of them. I want to check which server is my desired server. There are some ...
0
votes
1answer
141 views

I need Control loop help -

this is what I figured out in sorting an Array that has already had it's elements declared type int #!/bin/bash #sorting an "predeclared" array typeset -i store BigNum let store=0 BigNum=0 ...
3
votes
4answers
215 views

Bash: For loop with binary range keeping control value binary

Let's say I have two bash variables that contain binary values: a=0011 # decimal 3 b=1000 # decimal 8 Is there a way I can loop through all the possible values between $a and $b keeping it binary? ...
1
vote
1answer
41 views

for + array + args

I have problem with my for cycle, this is what I want: for arg do array[index]=(`find $arg -type l -maxdepth $depth -printf "%p\n" `) index++ done fi arg - positional arguments, only directories ...
1
vote
3answers
64 views

return the numeric value of a indexed variable rather than its name [duplicate]

The following piece of code illustrates my problem I'm afraid I oversimplified it way too much in the first round. #!/bin/bash dogLover=1 catLover=2 for ii in dog cat do ...
2
votes
2answers
460 views

Using for loop to brute-force a password

I just wanted to brute-force my old router but the for-loop was really amateur style. How to write a nice for-loop, if I only know the charaters included? Found already that page but it does not ...
2
votes
3answers
478 views

Command substitution in for loop not working

I want to keep all files not ending with .bat I tried for f in $(ls | egrep -v .bat); do echo $f; done and for f in $(eval ls | egrep -v .bat); do echo $f; done But both approaches yield the ...
0
votes
6answers
7k views

bash variables in for loop range [duplicate]

I want to print list of numbers from 1 to 100 and I use a for loop like the following: number=100 for num in {1..$number} do echo $num done When I execute the command it only prints {1..100} and ...
5
votes
3answers
679 views

Walking through files in directory randomly

How to change for track in *.mp3; do so that all .mp3 files in the current directory are walked through but in a random way?
2
votes
2answers
189 views

Why won't the for loop execute on directory

In the following script, the first for loop executes as expected, but not the second. I do not get any error, it seems that the script just hangs. HOME=/root/mydir DIR=$HOME/var DIRWORK=$HOME/Local ...
3
votes
4answers
5k views

Piping output to text file within a for loop

I'm trying to do the following within a for loop: Find files that satisfy a condition Echo the name of the files to a log file. Gzip the file. I can get the script to find the files and echo their ...
3
votes
3answers
252 views

${!FOO} and zsh

${!FOO} performs a double substitution in bash, meaning it takes the (string) value of FOO and uses it as a variable name. zsh doesn’t support this feature. Is there a way to make this work the same ...
1
vote
1answer
1k views

Why the behavior of while loop and for loop is different?

I am trying to read user and server details from file tempo.txt and then check the disk space usage of the file system on that unix account using another script server_disk_space.sh.But I am not able ...
7
votes
4answers
854 views

Avoiding errors due to unexpanded asterisk

In bash I often use for-loops such as the following for file in *.type; do sommecommand "$file"; done; to perform an operation for all files matching *.type. If no file with this ending is ...
18
votes
2answers
2k views

In bash, is it possible to use an integer variable in the loop control of a for loop?

I have the following bash script: #!/bin/bash upperlim=10 for i in {0..10} do echo $i done for i in {0..$upperlim} do echo $i done The first for loop (without the variable upperlim in the loop ...
0
votes
3answers
929 views

for loop with multiline data

I need to create a script with a loop through a list of items. I want to insert a string in the script. I tried: for i in " a b c"; do echo "test "$i done But that only outputs one string: test ...
0
votes
3answers
92 views

Why the code in a for loop is executed only in the first directory in a bash shell?

Under a directory called a there are many subfolders where I want to do something. The same for all. I do the following but it applies only to the first subdirectory: for i in "a/*" do ...
5
votes
1answer
8k views

In a bash shell script, writing a for loop that iterates over string values

In bash, I know that it is possible to write a for loop in which some loop control variable i iterates over specified integers. For example, I can write a bash shell script that prints the integers ...
7
votes
3answers
4k views

Multivariable For Loops

Is there a way to specify multiple variables (not just integers) in for loops in bash? I may have 2 files containing arbitrary text that i would need to work with. What i functionally need is ...
1
vote
1answer
134 views

What's the right way to reuse this one-liner?

I recently came up with the following one-liner: for f in *.mp3; do sha1sum $f | sed -r 's/[a-z]//g' | cut -c1-2 | awk '{ print ($1 >= 255) ? $1 - $1 + (1/3)*$1 : $1 }' | xargs -i id3v2 -T {} $f; ...
0
votes
3answers
3k views

Why does this incrementing for loop return a bad variable?

I'm trying to call this shell script from within the CLI of GRASS GIS: for (( day=5; day<367; day+5 )); do # commands that I've tested without a loop. done exit 0 returns Syntax error: Bad ...