首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >管道后的“未找到命令”

管道后的“未找到命令”
EN

Stack Overflow用户
提问于 2019-05-27 01:12:37
回答 1查看 558关注 0票数 0

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

我检查了它们是否安装在哪里,在最近的版本中,以及它们是否在$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

我承认我完全被弄糊涂了。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56315722

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档