管道后出现“找不到命令”

时间:2019-05-26 17:12:37

标签: macos shell path pipe homebrew

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

我检查了它们的安装位置/位置,最新版本以及是否在$ 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

我承认自己很困惑。

1 个答案:

答案 0 :(得分:0)

@Kamil Cuk 您所有的建议都可以通过复制粘贴实现。而且您对不可读的字符是正确的。

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

...而且由于我一直通过向上箭头键重复使用该行,因此gremlin在所有尝试中均保持不变。

感谢您的快速帮助!您可以将评论作为答案吗?