我试图进入目录 /cygdrive/c/Users/my dir/Documents
:
$ DOCS="/cygdrive/c/Users/my\ dir/Documents"
$ echo $DOCS
/cygdrive/c/Users/my\ dir/Documents
$ cd $DOCS
-bash: cd: /cygdrive/c/Users/my\: No such file or directory
$ cd /cygdrive/c/Users/my\ dir/Documents
(success)
当我手动输入时,后退空间会做转义字符的事情,但是当我使用变量 DOCS
的参数展开时则不会。
我尝试了其他变化,如没有反斜杠。
$ DOCS=/cygdrive/c/Users\ dir/Documents
$ echo $DOCS
/cygdrive/c/Users/my dir/Documents
$ cd $DOCS
-bash: cd: /cygdrive/c/Users/my: No such file or directory
或者
$ DOCS="/cygdrive/c/Users/my dir/Documents"
$ echo $DOCS
/cygdrive/c/Users/my dir/Documents
$ cd $DOCS
-bash: cd: /cygdrive/c/Users/my: No such file or directory
$HOME
也是如此:
$ echo $HOME
/home/my dir
cd $HOME
也不起作用。报价必须放在它的周围。
管他呢:
$ DOCS="\"/cygdrive/c/Users/my dir/Documents\""
$ echo $DOCS
"/cygdrive/c/Users/my dir/Documents"
$ cd $DOCS
-bash: cd: "/cygdrive/c/Users/my: No such file or directory