在〜.bash_profile中为具有包含空格的文件名的路径导出别名

时间:2017-11-08 03:55:10

标签: bash

我正在尝试在Mac中的bash_profile中添加别名。我尝试创建别名的文件的实际路径是

amar@admin:~/Library/Application Support/com.bohemiancoding.sketch3/Plugins 

$pwd

/Users/amar/Library/Application Support/com.bohemiancoding.sketch3/Plugins

我尝试了2个选项

选项#1

export sketch="/Users/amar/Library/Application\ Support/com.bohemiancoding.sketch3/Plugins"

这有错误,如

amar@admin:~$ echo $sketch
/Users/amar/Library/Application\ Support/com.bohemiancoding.sketch3/Plugins
amar@admin:~$ cd $sketch
-bash: cd: /Users/amar/Library/Application\: No such file or directory

选项#2

export sketch="/Users/amar/Library/Application Support/com.bohemiancoding.sketch3/Plugins"

这显示错误,如

amar@admin:~$ echo $sketch
/Users/amar/Library/Application Support/com.bohemiancoding.sketch3/Plugins
amar@admin:~$ cd $sketch
-bash: cd: /Users/amar/Library/Application: No such file or directory

问题接近此文件名Application Support

1 个答案:

答案 0 :(得分:3)

扩展时必须引用变量:

sketch="/Users/amar/Library/Application Support/com.bohemiancoding.sketch3/Plugins"
cd "$sketch"

报价不是可选的,你无能为力。