Problem with spaces in the path

Hi all,

I have a variable test has the following value assigned.. could you please help on doing cd or ls to the value in the varible ...

$echo $test
/bdm/sdd/compounds/AD4833XT/requests/clin/Watson_20090420/docs/MHRA\ Comments\ \&\ Responses
$cd $test
ksh: cd: bad argument count
$cd /bdm/sdd/compounds/AD4833XT/requests/clin/Watson_20090420/docs/MHRA\ Comments\ \&\ Responses
$pwd
/bdm/sdd/compounds/AD4833XT/requests/clin/Watson_20090420/docs/MHRA Comments & Responses
$ls $test
/bdm/sdd/compounds/AD4833XT/requests/clin/Watson_20090420/docs/MHRA\ not found
Comments\ not found
\&\ not found
Responses not found
$ls /bdm/sdd/compounds/AD4833XT/requests/clin/Watson_20090420/docs/MHRA\ Comments\ \&\ Responses
CMC Clinical

Why do you have a path with all kinds of special characters in the first place...and if you really have to then you need to put your variable in double quotes...

ls "$test"

I tried and got the following error

$ls "$test"
/bdm/sdd/compounds/AD4833XT/requests/clin/Watson_20090420/docs/MHRA\ Comments\ \&\ Responses not found

---------- Post updated at 12:36 PM ---------- Previous update was at 12:34 PM ----------

Those were the file created by a users, not me. I am writing a script in which i need to take the permissions on each directory... so i am working on this ans got this issue with file names with spaces and special characters..

The backslashes don't belong in the variable, because they don't actually exist in the name. They're just there in the tab-completion to get the whole name without the string splitting in spaces when un-quoted. So:

# unquoted
ls /bdm/sdd/compounds/AD4833XT/requests/clin/Watson_20090420/docs/MHRA\ Comments\ \&\ Responses
CMC Clinical
# quoted
ls "/bdm/sdd/compounds/AD4833XT/requests/clin/Watson_20090420/docs/MHRA Comments & Responses"

Note how the backslashes aren't needed when it's in quotes.