【发布时间】:2019-10-12 10:03:10
【问题描述】:
如果在管道之后调用某些命令,则会返回“找不到命令”。
我检查了它们是否安装/安装在哪里,在最近的版本中,以及它们是否在 $PATH 中。 背景:MacOS 10.14.5、gnu 实用程序和其他通过 homebrew 安装的命令,手动设置 $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
我还在管道后尝试了sort 和xargs:同样的行为。
可能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
我承认我完全糊涂了。
【问题讨论】:
-
嗯。试试
echo -e "${PATH//:/\\n}" | grep usr?还是echo -e ${PATH//:/\\n} |grep usr?还是echo -e ${PATH//:/\\n}|grep usr?如果你仔细看这里:-bash: grep: Command not found.bash:后面有两个空格,看起来 bash 正在从某个地方吃掉一个空格并将命令解释为' grep'。也许你在那里输入了一些不可读的字符,在另一个窗口中再试一次并重写它(不是复制)以确保。
标签: macos shell path pipe homebrew