Going to directory using bash variables doesn't work when directory names have spaces
- by gsingh2011
Let's say I want to store the following command in a variable
cd "/cygdrive/c/Program Files/"
So I do this
dir="cd \"/cygdrive/c/Program Files/\""
That should store the command to navigate to the Program Files directory, so when I type $dir it takes me to that directory. To check that the quotations have been properly escaped, I type
echo $dir
which gives me
cd "/cygdrive/c/Program Files/"
So everything should be working fine. However, when I type,
$dir
I get
bash: cd: "/cygdrive/c/Program: No such file or directory
What am I doing wrong? I'm using Cygwin, but I assume this problem applies to bash in general.