[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

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
0
sheepfarmer
Asked:
sheepfarmer
1 Solution
 
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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now