Tags

Suppose we have some file, say commands.txt, every line of which specifies the arguments to a particular command we would like to run.

For example, take the command cp -f and commands.txt as the following:

../../foo1.txt bar1.txt
../../foo2.txt bar2.txt

Then we would expect two commands to be executed.

cp -f ../../foo1.txt bar1.txt
cp -f ../../foo2.txt bar2.txt

The the following bash snippet performs this task.

OLDIFS=$IFS
export IFS="
"
for l in `cat commands.txt`
do
   eval "cp -f $l"
done
export IFS=$OLDIFS
Advertisements