spaces in bash variable path name

两盒软妹~` 提交于 2019-12-18 07:05:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!