I'd like to do something with each file of some type in a particular directory. I've written, in a bash script,
HANDIN_FILES=`find . -type f -printf "%f\n" | head -20 `
for i in $HANDIN_FILES
do
echo $i
done
as a kind of first version. This works great if there are no blanks in any filename. If there is a file silly name.txt
, then i
ends up being first silly
and then name.txt
, which is not what I want at all.
I know that I could put all the do ... done
stuff in a -exec
option in the find
command, but I'd like to preserve the list of files in a shell variable for later use as well. Can someone suggest a quick fix that'll cause i
to have the value silly name.txt
on one iteration through the loop?