【问题标题】:Error when adding alias to .profile in mac在 mac 中向 .profile 添加别名时出错
【发布时间】:2014-12-16 19:25:40
【问题描述】:

我在 Mac 上编辑了我的 .profile 文件,以便在终端中创建别名。我已添加:

alias goto_test="cd /Library/WebServer/Documents"

我保存 .profile 文件并运行:

source .profile

但是,终端返回错误:

-bash: alias: /Library/WebServer/Documents: not found

我做错了什么?

.

备注

当我在终端中执行cd /Library/WebServer/Documents 时,路径工作正常。

我注意到用alias show_test="ls" 定义别名会引发错误,因为它似乎试图用引号执行“ls”。

alias show_test=ls 不带引号也可以。

但是,使用不带引号的alias goto_test=cd ~/ 是行不通的,因为它是一个多字命令。

【问题讨论】:

    标签: bash terminal alias .profile


    【解决方案1】:

    在 OS X 中禁用智能引号。您的 ASCII 双引号正在被 bash 无法识别的花哨的倾斜 Unicode 引号所取代。

    这是问题的重现:

    $ cat profile                                                                
    alias goto_test=“cd /Library/WebServer/Documents”                            
    
    $ source profile                                                             
    bash: alias: /Library/WebServer/Documents”: not found                        
    
    $ shellcheck profile                                                         
    In profile line 1:                                                           
    alias goto_test=“cd /Library/WebServer/Documents”                            
                    ^-- SC1015: This is a unicode double quote. 
                                Delete and retype it.
    
    $ cat -vE profile                                                            
    alias goto_test=M-bM-^@M-^\cd /Library/WebServer/DocumentsM-bM-^@M-^]$ 
    

    【讨论】:

    • 很好(如果这是问题的话)。不要使用 TextEdit 来编辑 Unix 脚本等。使用开发编辑器,如 vim、pico 或 gmacs。这三个都是 Mac 的标准配置。或者,下载类似 TextWrangler 的内容。
    • 谢谢,这行得通。我想再补充一件事:这个解决方案早先发生在我身上,我尝试在 Sublime Text 中进行编辑。但是,我从 TextEdit 粘贴代码,并且 unicode 引号必须随粘贴一起转移。 (我不认为这是可能的。)一定要在开发编辑器中完成所有的输入。粘贴不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多