I'm trying to find .tif files in a directory tree and rename them prior to zipping them and moving them to another dir. this is my code:
cd $TMPPATH
pwd
ctr=0
for i in 'find . -name "*.tif"'
do
let "ctr+=1"
newtifname=$DATEDIR"_"$SEQ"_"$ctr".tif"
mv "$i" "$newtifname" | zip -j $output_zip_file -@ >> $LOG
done
When I execute this, I get the following error:
But when I cd to this directory (outside my script) and execute the same find command, I see a *.tif images.
Yes,
it appears that you want a command substitution in the for loop list of items:
$(find . -name "*.tif")
This is not the right way to do such a thing though, if any of the file names found contains white spaces or other pathological characters your script will fail.
This should be better implemented with a while loop, modifying the current IFS.
NO. You need a child process for find that the parent waits for:
for i in $find . -name "*.tif" )
backtics ` ` or the $( ) construct mean the same thing. You just found out why the backtic thing has problems - it is hard to see and easy to mess up. I used the $( ) thing because it is hard to mistake for something else.