【问题标题】:Alias command not found when running .bashrc运行 .bashrc 时找不到别名命令
【发布时间】:2016-03-17 11:03:18
【问题描述】:

我正在尝试像我经常做的那样做最简单的 shell 别名。

例如,这是我的 .bashrc(ZSH 和 .zshrc 也是如此):

alias ll=“ls -al”
alias edit_http=“open -e /etc/httpd/conf/httpd.conf”

这是我的 $PATH 变量:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

当我打开一个新的终端窗口时,我得到了这个:

-bash: alias: -al”: not found
-bash: alias: -e: not found
-bash: alias: /etc/httpd/conf/httpd.conf”: not found

这是我的 .bashrc 的 ls -al 结果:

-rwxr-xr-x@   1 ed    staff     78 Mar 17 03:55 .bashrc

奇怪的是,我可以在终端中输入它并且它可以工作:

alias ll="ls -al"

但不是来自 .bashrc 文件。

有什么建议吗?我已经检查了很多论坛条目,但到目前为止没有任何效果。

【问题讨论】:

    标签: macos bash shell terminal


    【解决方案1】:

    在将别名复制到您的 .bashrc 时似乎出了点问题。

    您最后使用了“错误”引号。将 替换为",它应该可以工作。 是 unicode,但您需要 ascii 引号。对于测试,您可以使用这个 .bashrc

    # bashrc example
    # won't work
    alias ll=“ls -al”
    # will work
    alias la="ls -al"
    

    您可以使用此代码验证您的问题:

    $ source .bashrc
    -bash: alias: -al”: not found
    $ ll
    -bash: “ls: command not found
    $ la
    total 0
    drwxr-xr-x   2 alneuman  staff    68 Mar 17 12:18 .
    drwxrwxrwx+ 70 alneuman  staff  2380 Mar 17 12:18 ..
    

    在 unix.stackexchange 上查看 here。有人有同样的问题。勇敢的新 unicode 世界;)

    【讨论】:

    • 就是这样。非常感谢!你的帖子让我看到了发生了什么。我使用“open -e”和 TextEdit 来编辑 .bashrc 文件,并且 Substitutions - Smart Quotes 已打开。一旦我把它关掉,一切都很好。成功!
    猜你喜欢
    • 2021-09-16
    • 2022-01-10
    • 2014-10-08
    • 2016-01-13
    • 1970-01-01
    相关资源
    最近更新 更多