bash 哦,我的 Zsh 具有一个别名的多个命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19255030/
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
Oh My Zsh multiple commands with one alias
提问by snakesonatoni
回答by simont
As you've discovered, you can chain commands in a single alias using ;
:
正如您所发现的,您可以使用;
以下命令在单个别名中链接命令:
alias update_my_gems="echo foo; echo bar"
Alternatively, you can write a function very easily in your ~/.zshrc
file:
或者,您可以非常轻松地在~/.zshrc
文件中编写一个函数:
update_my_gems() {
echo foo
echo bar
}
For readability, I'd personally go for a function for anything that's semi-complex.
为了可读性,我个人会为任何半复杂的东西寻找一个函数。
回答by cesartalves
If there are many commands, I find it useful to alias the execution of a .sh file located on my home directory
如果有很多命令,我发现将位于我的主目录中的 .sh 文件的执行别名化很有用
alias start_containers="./start-containers.sh"
To throw the alias inside the config file, you can do
要将别名放入配置文件中,您可以执行以下操作
echo alias start_containers="./start-containers.sh" >> ~/.zshrc