问题
Ugh. I hate bash escape sequences. What's the proper way to do this?
$ 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
I want to break all the things.
gaaaaaahhhhhhhhhhhhhhhhhh.
回答1:
The proper way is to quote the variable while expanding else word splitting would happen on whitespaces:
export SUBLPKG=~/"Library/Application Support/Sublime Text 2/Packages"
cd "$SUBLPKG"
You might also want to refer to Word Splitting in the manual.
Also refer to Word Splitting here.
来源:https://stackoverflow.com/questions/22889700/spaces-in-bash-variable-path-name