Why do I sometimes get 'sh: $'\302\211 ... ': command not found' in xterm/sh?

Solution 1:

It happens when I first attempt to paste a command from the clipboard, Linux-style (Ctrl+Shift+V) and when that doesn't work, paste with the mouse. Apparently the keyboard combination inserts an invisible character before the command. The solution is simple, don't use the keyboard to paste, or if you have, press Backspace before pasting with the mouse.

Solution 2:

The 0x89 provides a clue: with the default eightBitInput resource setting, xterm logically-ORs the input 8-bit codes to map them from 0-127 to 128-255:

  • tab is ^I is 0x9, and
  • ORed with 0x80 gives the odd 0x89.

You can fix the problem by not pressing your "meta" key at the same time you press tab.

The eightBitInput feature is old (dating from X11R4 in 1989), corresponding to the meta key feature. Much later, it was modified to work with UTF-8 in Patch #183 - 2003/12/26 - XFree86 4.3.99.903:

  • modify handling of eightBitInput resource in UTF-8 mode to translate the value into UTF-8. Otherwise an illegal UTF-8 code is sent to the application (report by Bram Moolenaar).

People using bash tend to assume that meta mode refers to prefixing things with an escape character, but have it backwards. See Alt-keys do not work in bash in the ncurses FAQ.

If you turn eightBitInput off, that would not solve this particular problem: xterm would send escapetab when you press metatab, which bash should object to...