bash变量路径名中的空格 [英] Spaces in bash variable path name
本文介绍了bash变量路径名中的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
执行此操作的正确方法是什么?
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
推荐答案
正确的方法是在扩展变量时引用该变量,否则在空白处会发生单词拆分:
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.
另请参阅分词此处.
这篇关于bash变量路径名中的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文