【问题标题】:Using grep command within .zshrc : No such file or directory在 .zshrc 中使用 grep 命令:没有这样的文件或目录
【发布时间】: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 的虚拟机中。找不到正确的原因或解决方案。

标签: linux ubuntu grep zsh


【解决方案1】:

使用 grep 的完整路径: /usr/bin/grep

【讨论】:

  • 我更新了问题。它也不起作用
猜你喜欢
  • 1970-01-01
  • 2018-08-14
  • 1970-01-01
  • 1970-01-01
  • 2021-03-01
  • 2021-05-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多