How to run a command for each number in a range

In bash, you can create loops using the builtin command for iterating through a range:

for i in {5..12}
do 
    specmd file${i}.awe
done

There are more options in for for other similar situations, I will leave here a link for that.

http://www.cyberciti.biz/faq/bash-for-loop/


I know this is an old question, but I could not resist.

No for loop required, no while loop required, just pure command-line bash:

echo file{5..12}.awe | xargs -n1 specmd

for f in file[5-9].awe file1[012].awe
do  : stuff with "$f" files
done

...not all globs are equal.

else you can do:

x=4
while  [ 13 -gt "$((x+=1))" ]
do     : stuff with "file$x.awe"
done

...which has the advantage of generating its iterator while iterating, and works by default in practically any scripted shell (as is also true of the globs).

Tags:

Shell