This question already has an answer here:

Very often, on my Mac, when I use the pipe (|) character followed by a space character, an invisible character will be inserted in between.

This is especially annoying when using the terminal, as it makes commands invalid.

If I type the following in iterm2, I often get the following:

ls | cat
zsh: command not found:  cat

If I hit the up-arrow-key to get my previous command, and then remove and reinsert the space between | and cat, the command will work.

When I copy paste the working and non working commands into a file, like this:

non-working: ls | cat
working: ls | cat

and open it in Hex Fiend it shows the following:

non-working: ls | cat
working: ls | cat

I've also experienced the same kind of issue in SublimeText2 using the square brackets ([]) followed by a space. So I don't believe its an issue with iTerm2.

marked as duplicate by DavidPostill Mar 30 '17 at 14:28

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Related to this, is there a way to have Terminal show invisible characters, similar to how text editors show them, e.g. as a gray bullet? – jelovirt Jan 26 '13 at 18:43

What happens is that you keep pressing with the space bar, which inserts a non-breaking space, known in HTML through the   reference. This non-breaking space is useful in text processing where you want certain words to stick together, like the "OS" and "X" in "OS X".

Obviously, this is a unicode character (00A0), and therefore most of the command-line utilities will fail, such as bash seeing _cat (where _ is the non-breaking space), and Hex Fiend just using a bad representation for it. Some editors on the other hand will just silently strip it out (e.g. this editor right here), while others even have a special representation for it (e.g. TextMate showing a dot instead of the blank space).

There are two solutions:

  • This does indeed appear to be the issue. Can't believe I haven't caught this before. I guess a solution would be to remap space combined with the modifier to a regular space character. – nifty Apr 24 '12 at 8:12
  • Is it possible to make the Terminal display nbsp as a reverse character or some sort, so you would instantly see it when you mistype? – forthrin Mar 24 '18 at 9:11
  • @forthrin Good question. I don't know of any way to do that, other than messing with your locale settings such that non-ASCII characters cannot be displayed properly. – slhck Mar 24 '18 at 10:18

Not the answer you're looking for? Browse other questions tagged or ask your own question.