Tuesday, 27 March 2007

An Inline Shell Script with a For Loop

You can easily go through a list of items using a for loop. Here's an example of copying selected contents of originalDir to destinationDir via the command line.

#sh
#for i in `cat /home/esofthub/mylist.dat`
#do
#cp -pr /originalDir/$i /destinationDir/.
#echo $i done
#done


sh – shell

cat – lists each item in the list one iteration at a time

cp – the copy utility for a local workstation

-pr – these options preserve the permission and copies recursively

echo – lists the item copied

No comments: