cannot stat error

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.

Anyone see what I'm doing wrong?

for i in `find . -name "*.tif"`

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.

1 Like

So just remove single quotes? I tried this, and got this result:

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.

1 Like

These backticks look like ordinary quotes to me :wink:

Thank you radoulov and jim (for the explanation). It's working now.