Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
369 views
in Technique[技术] by (71.8m points)

osx lion - Bash piping in OSX prompts command not found, sometimes

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

"xC2xA0": " "

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...