OSX 中的 Bash 管道有时会提示找不到命令
在 OSX 终端中:
du -h | sort -nr
-bash: sort: command not found
which sort
/usr/bin/sort
奇怪的是:我尝试重现错误,它似乎完全是随机的。我的 PATH 回显:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/texbin:/Users/sytycs/.rvm/bin
这只发生在管道传输时,并且发生在 grep
、more
、less
等情况下。 知道是什么原因造成的吗?
In the OSX terminal :
du -h | sort -nr
-bash: sort: command not found
which sort
/usr/bin/sort
The weird thing is: I tried reproducing the error and it seems to be totally random. My PATH echoed:
/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:/usr/local/git/bin:/usr/texbin:/Users/sytycs/.rvm/bin
This only occurs when piping and happens with grep
, more
, less
etc.
Any idea what is causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
发生这种情况可能是因为您使用了非美国布局的键盘布局(我也遇到过)。在德语布局中,使用 Alt+7 键入管道,因此很有可能按 Alt+Space 之后,这将产生一个不间断空格。
快速解决方案:将该行添加
到您的
~/.inputrc
(如果您使用的是 bash)。这会将不间断空格映射到正常空格,这应该可以解决问题。如果您想要更多详细信息(或者如果您对如何追踪此类问题感兴趣),我写了 前段时间关于它的博客文章。
This likely happens because you use a keyboard layout with a non-US layout (happened to me too). On German layouts, the pipe is typed with Alt+7, so chances are high that you press Alt+Space afterwards, which will produce a non-breaking space.
A quick solution: Add the line
to your
~/.inputrc
(if you are using bash). This will map non-breaking spaces to normal ones which should solve the problem.If you want more detail (or if you are interested in how you can track down these kinds of issues), I wrote a blog post about it some time ago.
那个空间不是一个空间。删除并替换它。
That space is not a space. Erase and replace it.
~/.inputrc 的技巧对 zsh 不起作用。但在这里你可以配置 iTerm 在输入 alt+space 时发送一个空格,例如
The trick with ~/.inputrc doesn't work for zsh. But here you can configure iTerm to send a space when you type alt+space, for instance
当你吹奏时,Bash 对空格非常敏感。将它们全部删除。
我通过运行此命令遇到了同样的问题:
错误如下:
然后我删除了所有空格并解决了:
Bash is so sensitive to space when you are piping. Remove them all.
I was facing the same problem by running this command:
the errors were as here:
then I removed all the spaced and it got resolved: