Iterate through find results in bash

find [insert parameters here] | while read line
do [insert stuff to do here]
done

You can use the variable $line here, for the path to each file that ‘find’ finds.  And you can use `(basename $line)` to get the filename only (removing the path).  For some reason, I couldn’t do, eg NAME=`(basename $line)` or NAME=$(basename $line).  (Well, I could, it worked, however at the end of the script it gave me basename missing operand error.  If anyone could enlighten me…

Leave a Reply

Your email address will not be published. Required fields are marked *