I had this problem using bash
on my MacBook with OS X. Pipes didn’t work any more. A command like
$ ls | wc
would give me the response
-bash: wc: command not found
I thought I’d lost the wc
command. But locate
found it. I checked my PATH. It was correct. Then I found that many other commands wouldn’t work. Even less
didn’t work. However, if I used the lost command without a pipe, e.g.:
$ wc *.js
then it would be found.
What was going on?
Eventually in desperation I copied the command and pasted it into a text file, then ran od
on it.
$ od -bc x
0000000 154 163 040 174 302 240 167 143 012
__________ l s | ** w c \n
0000012
And there I found the culprit.
After the vertical bar pipe symbol I expected to see octal 040, the code for a space. That’s what you see before the pipe symbol. But what I saw here was 302 followed by 240, i.e. two bytes, not one. “302 240” is a UTF-8 encoded string (C2 A0) for Unicode code point A0 and represents a non breaking space character.
The cause?
I have a German keyboard. To get a pipe symbol ‘|
‘ I have to hold down the [alt]-key and press the 7-key (Shift-7 is forward-slash ‘/
’). When I then typed the space after the pipe, I wasn’t letting go of the [alt]-key fast enough, so I was typing [alt]-space instead of a regular space. Bash
interpreted the non-whitespace [alt]-space character as part of the command name, and couldn’t find anything to match. If I let go of the [alt]-key before typing the space, all was well.
It turns out that you can make bash interpret the non breaking space as a regular space. Just add the following lines to ~/.inputrc
:
# Map (UTF-8) non-breaking space to regular space,
# in case the user accidentally types Option-Space
# or [alt]-Space when they meant Space.
"\xC2\xA0": " "
Thanks to Xtra Crispy at https://discussions.apple.com/ for that tip.
I hope you find this before you waste as much time as I did trying to find out what was going wrong. Have fun bash
ing.