Here's a highly oversimplified example of what I'm trying to do, but exactly illustrates the problem I'm having and should be enough to provide a workable solution.
Here's a simple script that should ls a particular folder, and put the output into a text file:
Code:
#!/bin/bash
path1=/home/name/Black\ \&\ Red
list=/home/name/Black\ \&\ Red.lst
ls $path1 | sort >> $list
exit
As you can see, I have the & character and some spaces in the filename that are being escaped with the backslash.
I've tried the plain escape as above, and I've tried wrapping the path-/file names in both single and double quotes (not at the same time, obviously) both with and without the escape character, but Bash always gives the same error(s) - something along the lines of:
Quote:
file/folder 'Black' not found
file/folder '&' not found
file/folder 'Red' not found
Also, $list ends up just being titled 'Black', so the error is present in that line as well.
One thing I have noticed is that if I get rid of the spaces in the filenames and just escape the '&' symbol, I don't get the error. I, however, like having spaces in my filenames.
How can I properly escape and/or wrap those filenames so they're correctly interpreted by the shell?