Bash shell unwanted file expansion at the space character

I'm trying to process a bunch of subdirectories that have spaces in the name.
The following bash script is expanding $thisfile at the space, so the file command fails as it never gets the full path/filename
How can this be fixed.

Oddly,
  echo $thisfile
does not expand $thisfile

Thanks
SF


==============================
find . -print | while read thisfile
do
file $thisfile
done
sheepfarmerAsked:
Who is Participating?
 
sunnycoderCommented:
Hi sheepfarmer,

Enclose the parameter in double quotes

file "$thisfile"
---------------------------------
echo $thisfile
does not expand $thisfile

This would happen if you are executing the echo command in a different shell. Typically scripts are launched in sub-shell. Hence variables which have been in the script would not be visible on the main shell.

Cheers!
Sunnycoder
0
 
sheepfarmerAuthor Commented:
Thanks for the solution - embarrassingly simple :)
SF
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.