【发布时间】:2021-05-11 15:06:02
【问题描述】:
我在 .zshrc 中有一个函数(shell 是 zsh)。
test1(){
toprint=$(ps -ef | grep $1)
echo $toprint
}
提供以下输出。
asiri ~ test1 gradle
grep: gradle: No such file or directory
经过一番研究,我发现语法高亮插件添加了一个别名
zsh -x 2>zsh.trace
exit
grep 'alias.*grep' zsh.trace
#part of output
+/home/asiri/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh:593> eval $'.... long string here..
+(eval):132> alias 'grep=grep --color=auto --exclude-dir={.bzr,CVS,.git,.hg,.svn,.idea,.tox}'
由于它是作为脚本的一部分添加的,因此我无法将其注释掉。 但是如果没有这样的别名集(我的另一个 linux vm 之一),上面的函数可以正常工作。 请告知是否有解决此问题的方法。 我也尝试了“unalias”,将其添加到 .zshrc 文件中。它也没有解决问题。 谢谢!
【问题讨论】:
-
使用
ps -ef | \grep "$1"或ps -ef | command grep "$1"甚至更好地使用pgrep -
以上都不是:-(
-
我无法使用您提供的函数和别名重现此问题。您可以在您的问题中添加minimal, reproducible example 吗?
-
我可以在我的环境中重现这个。我不是 100% 肯定会因为别名而发生这种情况。可能还有另一个我不知道的原因。但这发生在我的几个甚至没有安装 zsh 的虚拟机中。找不到正确的原因或解决方案。