Monday, 3 August 2009

Bash Scripting: for loop

Sometimes you want to run a program over and over with different parameters, you can do this with bash script wrapped around your program to cover a range of numbers:

for ((i=5;i<=15;i++));do echo ${i};done
So you could do something like this:

for ((i=0;i<=10;i++));do fancy_program --option ${i} --output ${i}_output.out;done
Or even something like this:

for f in *.fas;
do for ((i=0;i<=10;i++));
do fancy_program --input ${f} -n ${i} -o $(basename ${f} .fas)_${i}_output.out; done;
To loop through all files and all numbers. Of course you probably want to do this by submitting the jobs to a computing cluster, using bsub for example with LSF, otherwise thing might get a bit slow.

No comments:

Post a Comment