管道后“命令未找到”

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (53)

如果在管道之后调用它们,则某些命令会返回“未找到命令”。

我检查了它们是否安装在哪里,以及最近的版本,以及它们是否在$ PATH中。背景:MacOS 10.14.5,gnu实用程序和其他通过自制软件安装的命令,手动设置$ PATHS和$ MANPATHS。

$ echo -e ${PATH//:/\\n} | cut -d '/' -f 1
-bash:  cut: Command not found.
$ echo -e ${PATH//:/\\n} | grep '/usr/'
-bash:  grep: Command not found.

$ which cut
/usr/local/opt/coreutils/libexec/gnubin/cut
$ which grep
/usr/local/opt/grep/libexec/gnubin/grep

$ cut --version
cut (GNU coreutils) 8.31... 
$ grep --version
grep (GNU grep) 3.3...

$ bash --version
GNU bash, Version 5.0.7(1)-release (x86_64-apple-darwin18.5.0)...

$ echo -e ${PATH//:/\\n}
/usr/local/opt/openssl/bin
/usr/local/opt/coreutils/libexec/gnubin
/usr/local/opt/ed/libexec/gnubin
/usr/local/opt/findutils/libexec/gnubin
/usr/local/opt/gawk/libexec/gnubin
/usr/local/opt/gnu-indent/libexec/gnubin
/usr/local/opt/gnu-sed/libexec/gnubin
/usr/local/opt/gnu-tar/libexec/gnubin
/usr/local/opt/gnu-time/libexec/gnubin
/usr/local/opt/gnu-units/libexec/gnubin
/usr/local/opt/gnu-which/libexec/gnubin
/usr/local/opt/grep/libexec/gnubin
/usr/local/opt/inetutils/libexec/gnubin
/usr/local/opt/make/libexec/gnubin
/Users/xxxx/.jenv/shims
/Users/xxxx/.jenv/bin
/usr/local/opt/icu4c/sbin
/usr/local/opt/icu4c/bin
/usr/local/opt/gettext/bin
/usr/local/opt/binutils/bin
/usr/local/bin
/usr/local/sbin
/usr/bin
/bin
/usr/sbin
/sbin
/opt/X11/bin
/usr/local/opt/e2fsprogs/bin
/usr/local/opt/e2fsprogs/sbin

这些命令可以在单行和其他多行输入中工作:

$ echo "asdfdfasdfsadf" | cut -c 4-8
fdfas
$ echo "asdfdfasdfsadf" | grep 'df'
asdfdfasdfsadf
$ echo "asdfdfasdfsadf" | grep -v 'df'
$ ls -l | grep aps
drwx------   25 xxxx staff  800 Mai 17 23:33 Maps

我也试过sortxargs在管道之后:同样的行为。

也许多线返回echo -e ${PATH//:/\\n}是罪魁祸首,或者安装/设置是否有问题?

后者更有可能,因为:

$ which cut
/usr/local/opt/coreutils/libexec/gnubin/cut
$ whereis cut
/usr/bin/cut
$ which grep
/usr/local/opt/grep/libexec/gnubin/grep
$ whereis grep
/usr/bin/grep

我承认被彻底搞糊涂了。

提问于
用户回答回答于

@Kamil Cuk通过复制粘贴,您的所有建议都有效。你对这个难以理解的角色说得对。

我在BBEdit中打开了bash历史记录并查找了不寻常的字符,并在以下命令之间找到了\x{A0}(不间断空格)|

...因为我总是通过向上箭头键重新使用该行,所以gremlin在所有尝试中都持续存在。

谢谢你的快速帮助!你能评论一下答案吗?

扫码关注云+社区

领取腾讯云代金券