bash ZSH 无法识别我的别名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14286844/
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
ZSH not recognizing my aliases?
提问by o_O
Using iTerm2 with zsh and it isn't recognizing my aliases. Sometimes I have to work in an IDE and can't just easily vim something and the stupid people thought it a good idea to name their applications like MyReallyLongApplicationName.app and since .html files open by default in browsers, I have to:
将 iTerm2 与 zsh 一起使用,但无法识别我的别名。有时我必须在 IDE 中工作,不能轻易地 vim 某些东西,愚蠢的人认为将他们的应用程序命名为 MyReallyLongApplicationName.app 是个好主意,因为 .html 文件在浏览器中默认打开,我必须:
open -a MyReallyLongApplicationName.app something.html
I have an alias in my .zshrc like:
我的 .zshrc 中有一个别名,例如:
alias ide="open -a MyReallyLongApplicationName.app"
But zsh won't recognize my aliases. I tried another one just to see if it was me but none of the aliases I create are recognized. Just get "zsh: command not found: ide" or whatever.
但是 zsh 不会识别我的别名。我尝试了另一个只是为了看看是不是我,但我创建的别名都没有被识别。只需获取“zsh:找不到命令:ide”或其他任何内容。
So I'm not sure what I'm doing wrong and I've been searching around all day trying to fix things in zsh and the like. As a note, I'm not a pro at Linux/Unix systems so if you're too technical and vague I probably won't understand what you're telling me.
所以我不确定我做错了什么,我一整天都在四处寻找,试图修复 zsh 之类的东西。请注意,我不是 Linux/Unix 系统的专业人士,所以如果你太技术化和含糊不清,我可能不会理解你在告诉我什么。
Thanks!
谢谢!
回答by ShawnW.
if you do a very simple alias in zsh, does it work? open your .zshrc file, and add the following line:
如果你在 zsh 中做一个非常简单的别名,它会起作用吗?打开您的 .zshrc 文件,并添加以下行:
alias ls='ls -GpF'
after adding that line, type this line in your Terminal:
添加该行后,在您的终端中输入此行:
source ~/.zshrc
tell us what happens. Also, just for shiggles, make sure you are using single quotes vs. double quotes, I have seen that make a difference in the past on different versions of shells/OS/whatnot.
告诉我们会发生什么。另外,对于 shiggles,请确保您使用单引号与双引号,我已经看到过去在不同版本的 shell/OS/whatnot 上有所不同。
回答by dsteplight
Add "source ~/.bash_profile" to your ~/.zsh config file.
将“source ~/.bash_profile”添加到你的 ~/.zsh 配置文件中。
回答by json25
Put this line:
把这一行:
/source: 'source ~/.bash_profile' into ~/.zshrc
回答by user1854182
Sometimes the simple solution is what we need... Add "source ~/.bash_profile" to your ~/.zshrc config file
有时我们需要简单的解决方案......将“source ~/.bash_profile”添加到你的 ~/.zshrc 配置文件
echo source ~/.bash_profile >> ~/.zshrc
回答by Aditya
After saving changes in ~/.zshrc
file, open a new shell window and execute the command in it.
在~/.zshrc
文件中保存更改后,打开一个新的 shell 窗口并执行其中的命令。
回答by Antonio
Make sure the double quotes are actual double quotes and not some other character which looks like double quotes.
确保双引号是实际的双引号,而不是其他看起来像双引号的字符。
I was editing ~/.zsh-aliases in OSX - TextEdit, which, when hitting the double quotes key substituted it for another special double quotes character, which is not what ZSH expects.
我在 OSX - TextEdit 中编辑 ~/.zsh-aliases,当点击双引号键时,将它替换为另一个特殊的双引号字符,这不是 ZSH 所期望的。
After editing the alias file with Sublime and replacing the old double quotes with actual double quotes everything runs just fine.
使用 Sublime 编辑别名文件并将旧的双引号替换为实际的双引号后,一切运行正常。
Hope this helps.
希望这可以帮助。
回答by Abram
I needed to manually add the alias to my zsh config file and then run the source command on it.
我需要手动将别名添加到我的 zsh 配置文件中,然后在其上运行 source 命令。
echo alias this='some command' >> ~/.zshrc
source ~/.zshrc
回答by Mahund
I had all my aliases on ~/.bash_profile
, so i added at the last line on ~/.zshrc
the following line: . ~/.bash_profile
and it worked for me.
我的所有别名都打开了~/.bash_profile
,所以我~/.zshrc
在下一行的最后一行添加了:. ~/.bash_profile
它对我有用。
回答by sunny rai
Need to create a profile for .zshrc and register the alias into it. (only if the profile isn't available)
需要为 .zshrc 创建配置文件并将别名注册到其中。(仅当配置文件不可用时)
cd ~
touch .zshrc && open .zshrc
add all the alias in .zshrc file
source ~/.zshrc
close and re-open terminal and run the alias.
关闭并重新打开终端并运行别名。