I'm trying to build a script that I need to be quite able to manage directory with spaces or/and backslashes in their name or not.
Inside a bash script or directly on bash shell using variables for testing, I cannot change to a directory with escaped spaces in it, I can do it manually, but if I put it in a variable and I try to change directory using that variable I cannot.
EXAMPLE:
directory I want to cd to :
MY\ DIRECTORY\ WITH\ STRANGE\ \[CHARACTERS\]
in bash prompt I can cd to it :
cd MY\ DIRECTORY\ WITH\ STRANGE\ \[CHARACTERS\]
but if I put the director name in a variable I cannot :
TEST="MY\ DIRECTORY\ WITH\ STRANGE\ \[CHARACTERS\]"
cd "$TEST"
-bash: cd:MY\ DIRECTORY\ WITH\ STRANGE\ \[CHARACTERS\]: no such file or directory
So, is there a way to handle backslash in bash shell in a clean transparent way ?
I could remove backslashes from the string, but that introduce some tricky variable expand problems with directory names...