Tuesday, October 20, 2009

Looping in bash for multiple operations

Just learned that bash also supports looping that can be used to do the multiple operations on the files in a given folder.

for old in *.png; do  convert $old `basename $old .png`.eps;done

converts all the png files in a given folder to postscript file.

If there are i1.png, i2.png and i3.png then expansion of above loop will be
convert i1.png e1.eps
convert i2.png e2.eps
convert i3.png e3.eps

Note there is space between $old and .png

Similarly renaming *.png to mt_*.png
for old in *.png; do cp $old my_.`basename $old .png`;done

No comments: