Bash 别名:找不到命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33135897/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:06:59  来源:igfitidea点击:

Bash alias: command not found

macosbashalias

提问by Bill L

I'm trying to setup a simple alias to move me into my Developer folder on my machine. However, after setting it up, I get a weird error:

我正在尝试设置一个简单的别名,以便将我移动到我机器上的 Developer 文件夹中。但是,设置后,我收到一个奇怪的错误:

-bash: dv: command not found

I setup my alias in .bashrc like so:

我在 .bashrc 中设置了我的别名,如下所示:

alias dv='cd Developer/'

I use it by just typing dv, and then get that error. Does anyone see any syntax errors or something I'm missing here for aliases?

我只输入 就使用它dv,然后得到那个错误。有没有人看到任何语法错误或我在这里缺少别名的东西?

回答by pushkin

Run bashand then try the command.

运行bash然后尝试命令。

Alternatively, put it in ~/.bash_profilewhich should be loaded automatically.

或者,把它放在~/.bash_profile应该自动加载的地方。

回答by nneonneo

.bashrcis only read on startup. If you justmodified your .bashrcthen you need to get a new shell or get your current shell to see the changes applied:

.bashrc仅在启动时读取。如果您刚刚修改了您的,.bashrc那么您需要获得一个新的 shell 或获取当前的 shell 以查看应用的更改:

  • source ~/.bashrcin your current shell (although this may cause some startup items to run twice, which could cause other issues)
  • exec bashto get a new shell
  • just open a new Terminal window
  • source ~/.bashrc在您当前的 shell 中(尽管这可能会导致某些启动项运行两次,从而导致其他问题)
  • exec bash得到一个新的外壳
  • 只需打开一个新的终端窗口

回答by Mohan Raj

Error:

错误:

-bash: alias: cd /opt/logs: not found alias log= "cd/opt/logs"

-bash: 别名: cd /opt/logs: 未找到别名log="cd/opt/logs"

Solution :

解决方案 :

Ensure there is no space after the =symbol

确保=符号后没有空格

log="cd**  /opt/logs"

回答by Sparkzz

Make sure the following line is present inside .bash_profile

确保里面有以下行 .bash_profile

test -f ~/.bashrc && . ~/.bashrc

test -f ~/.bashrc && . ~/.bashrc

If not then add it to the beginning. This code is used by .bash_profileto load up .bashrc. If this line is not present inside .bash_profilethen anything you type inside .bashrcwill not be loaded.

如果没有,则将其添加到开头。此代码用于.bash_profile加载.bashrc. 如果此行不在里面,.bash_profile那么您在里面输入的任何内容.bashrc都不会被加载。

回答by Lucas Coelho

Another solution is to call your command with bash using -i -c option:

另一个解决方案是使用 -i -c 选项通过 bash 调用您的命令:

bash -i -c my_alias

回答by Ev0oD

I had the same issue but the weirdest solution. I was copying it from Windows machine to OS X and for some reason, the spaces used were different and when I replaced them with normal spaces, it worked. It was not tabs, I have no idea what it was.

我有同样的问题,但最奇怪的解决方案。我正在将它从 Windows 机器复制到 OS X,出于某种原因,使用的空格不同,当我用普通空格替换它们时,它起作用了。它不是标签,我不知道它是什么。