为什么我的终端别名失败了

时间:2015-02-27 19:30:23

标签: macos terminal

我读这个: http://www.maclife.com/article/columns/terminal_101_creating_aliases_commands

我在bash个人资料中写道: alias workspace =' cd Documents / workspace'

然而,我得到以下内容:

-bash: alias: workspace: not found
-bash: alias: =: not found
-bash: alias: cd Documents/workspace: not found

当我获取文件时。发生了什么事?

我在SO上搜索并发现:.bash_profile aliases: command not found但我没有使用双引号

1 个答案:

答案 0 :(得分:2)

请考虑删除=符号周围的空格。

供参考:http://www.gnu.org/software/bash/manual/bashref.html#Bash-Builtins

这不是在mac上,但仍然是bash:

$ cat with-spaces.sh
alias workspace = 'cd Documents/workspace'
$ . with-spaces.sh
./with-spaces.sh: line 1: alias: workspace: not found
./with-spaces.sh: line 1: alias: =: not found
./with-spaces.sh: line 1: alias: cd Documents/workspace: not found
$ # checking result...
$ alias workspace
bash: alias: workspace: not found

$ cat without-spaces.sh
alias workspace='cd Documents/workspace'
$ . without-spaces.sh
$ # checking result...
$ alias workspace
alias workspace='cd Documents/workspace'