唉。我讨厌bash转义序列。这样做的正确方法是什么?
$ export SUBLPKG=~/"Library/Application Support/Sublime Text 2/Packages"
$ cd $SUBLPKG
-bash: cd: /Users/$ME/Library/Application: No such file or directory
$ export SUBLPKG=~/"Library/Application\ Support/Sublime\ Text\ 2/Packages"
$echo $SUBLPKG
/Users/$ME/Library/Application\ Support/Sublime\ Text\ 2/Packages
$ cd $SUBLPKG
-bash: cd: /Users/$ME/Library/Application\: No such file or directory
我想打破所有的事情。
gaaaaaahhhhhhhhhhhhhhhhhh。
答案 0 :(得分:5)
正确的方法是在扩展时引用变量,否则会在空格上发生单词拆分:
export SUBLPKG=~/"Library/Application Support/Sublime Text 2/Packages"
cd "$SUBLPKG"
您可能还想参考手册中的Word Splitting。
另请参阅Word拆分here。