Whitespace Issues

Hello forums!

I've been tinkering with a shell script to partition and restore content to a drive based on a type of file in a given directory. My goal is for my script to assemble several restore images, partition the drive based on the images and to then restore those images to the partitions on the drive. Its going to be a multi-boot drive for troubleshooting different systems. Everything is going fine so long as the path to my "configuration" directory does not contain whitespaces.

Here is a snippet:

for file in `ls "/test folder"/*.ext`; do echo "$file"; done

The result is unusable:

/test
folder/test1.ext
/test
folder/test2.ext
/test
folder/test3.ext

I've tried single and double quoting all over the place and I can't find the correct usage. All I'm looking for is this:

/test folder/test1.ext
/test folder/test2.ext
/test folder/test3.ext

The "configuration" folder in my actual script is a variable passed on from another call earlier in the script. I know I could use:

for file in `ls /test\ folder/*.ext`; do echo "$file"; done

but because the "/test folder" is a variable grepped from the output of a function that only gives human readable output, I'm stuck.

Thanks for any help - I've been working on this line of my script for 3 days now and I can't figure it out. I'm always in awe of how well some folks have mastered the command line. Thanks again!

  • robbie -

Not only is there no need for ls, but it's breaking your script.

Use the wildcards directly:

for file in "/test folder/"*.ext