Going to directory using bash variables doesn't work when directory names have spaces
Posted
by
gsingh2011
on Super User
See other posts from Super User
or by gsingh2011
Published on 2011-11-19T20:44:17Z
Indexed on
2012/06/28
9:18 UTC
Read the original article
Hit count: 380
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.
© Super User or respective owner