【发布时间】:2014-08-27 16:09:41
【问题描述】:
我尝试在 zsh 的函数中定义并使用别名。它不起作用。为什么不呢?我可以绕过它吗?
% cat > test
alias_problem () {
alias hithere="echo Hi there!"
hithere
}
^D
% source test
% alias_problem
alias_problem:2: command not found: hithere
% hithere
Hi there!
% wtf?
zsh: no matches found: wtf?
理想情况下,运行 alias_problem 会打印出Hi there! 谁能解释发生了什么?有没有办法绕过它?
背景:我想创建一个函数来创建多个别名,然后运行其中一个。类似的东西
myfuncA () {
alias alias1=...
alias alias2=...
alias1
}
这样我就可以使用多个命令设置环境。我将有第二个函数将别名切换到不同的集合。
我应该只使用函数吗?无论如何,有什么理由在 zsh 中使用别名而不是函数?我想知道发生了什么,只是想知道以后如何避免。
谢谢:)
--彼得
【问题讨论】:
标签: function alias zsh operator-precedence