user2854544
user2854544

Reputation: 901

After a pipe the command is considered prefixed with a space

Sometimes on my terminal (Ubuntu) when I type:

ls | grep toto

I get this error:

 grep: command not found*

Notice that the shell is writing grep prefixed by a space. How can this be possible?

Upvotes: 12

Views: 3780

Answers (2)

Andre Miras
Andre Miras

Reputation: 3840

To complete Gilles answer, you can disable this behavior in Ubuntu/Gnome by replacing non-breakable space character by usual space in keyboard layout settings.

Settings -> Keyboard -> Layout -> Options, and select "Using space key to input non-breakable space character" and set it to: "Usual space at any level".

Or from the command line

setxkbmap -option "nbsp:none"

I found this fix in http://my.opera.com/nicomen/blog/unrecognized-character-xc2.

This was also annoying on French keyboard for Perl scripts when using curly brackets or in Python when using hash sign for comments followed by a space.

Upvotes: 6

<Checks the source of your original question>

<pre style="width:650px; white-space:pre-wrap">Sometimes on my terminal (Ubuntu) when I type :

ls |&#160;grep toto

Thank you for copy-pasting the actual line! (But you didn't copy-paste the error message, naughty you!) See the problem? You have an unbreakable space after the pipe symbol. Shells only understand ASCII characters; all non-ASCII characters, including U+00A0 NO-BREAK SPACE, are treated as word constituents, so that unbreakable space is treated as part of the word that's in command name position.

You're presumably using a keyboard layout where you need to hold down AltGr to type |. Make sure to release the AltGr modifier so as not to accidentally type AltGr+Space instead of Space. Note that you don't need a space there, you can type ls |grep toto if that's easier on your fingers.

Upvotes: 30

Related Questions