Monday, November 15, 2010

C2 A0 characters confusing bash?

Have you had a perfectly typed shell command fail on you, like this :

user@host:$ ps auxww | grep java
 grep: command not found


Here is the hex output of a correct "grep" and an incorrect "grep" command line:

user@host$ hexdump -C /tmp/x
00000000  70 73 20 61 75 78 77 77  20 7c 20 67 72 65 70 20  |ps auxww | grep |
00000010  6a 61 76 61 0a                                    |java.|
00000015
user@host$ hexdump -C /tmp/y
00000000  70 73 20 61 75 78 77 77  20 7c c2 a0 67 72 65 70  |ps auxww |..grep|
00000010  20 6a 61 76 61 0a                                 | java.|
00000016


The second output is the faulty one, notice the characters "C2 A0" cause the problem. A0 is the non-breaking space, and somehow, my keyboard at times produces these instead of "20" for the space character, thus confusing the shell.

This is on an ssh session to Linux 2.6, from a Mac.

4 comments:

sebleblanc said...

I also have this problem. It happens frequently. I am using Guake on a XFCE box.

Steve K said...

just happened to me. major WTF. found you via google searching for c2a0.

Anonymous said...

Vitko: the same for me, I wonder what is the problem?

Anonymous said...

the same for me, it happened while I was using Macintosh terminal. I found Dashboard Stickies replaces space characters with C2A0.