User Tools

Site Tools


This is an old revision of the document!

Repeat n times the same command with different arguments


  • If you need to process several files:

for i in `cat file_with_the_names_each_one_in_a_different_line`; do echo $i ; done

This actually prints the names of the files to process

  • If you do not have the names, but they are in the same directory:

for i in `ls -1 *.pdb`; do echo $i ; done

  • If you need to repeat n times the command

for i in `seq 1 5`; do echo “This is the iteration $i” ; done

Script version

One-liners also work for scripts but, if you need to make the structure clear:

for i in `ls -1 *.pdb`; do
echo $i

n-times_commands.1457360938.txt.gz · Last modified: 2016/03/07 14:28 by root