Bash displays international characters as escape sequences

bashinputrcreadline

When I press certain keys (e.g. German umlauts) in the bash command line, I get escape sequences. For example, ß gives me \303. These escape sequences are treated as single characters, so one backspace deletes the whole sequence. The character is just displayed wrong on the command line, but it is interpreted correctly, for example typing echo ß gives:

$ echo \303
ß

I guess it has problems with non 7-bit-ASCII characters. In every other place, these work fine however. I can use them in vim or display them with cat, and also unicode characters work fine.

How can I make bash display these characters correctly?


For the record,

TERM=xterm-256color
LANG=en_US.UTF-8

and from my .inputrc:

set input-meta on      # Enable Meta input with eighth bit set
set meta-flag on       # Synonym for the above
set convert-meta off   # Do NOT strip the eighth bit
set output-meta on     # Enable Meta output with eighth bit set

output of stty -a

speed 38400 baud; rows 24; columns 80; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?;
swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;
lnext = ^V; flush = ^O; min = 1; time = 0;
-parenb -parodd cs8 -hupcl -cstopb cread -clocal -crtscts -cdtrdsr
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff
-iuclc ixany imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt
echoctl echoke

This Stackoverflow question shows the same symptom, but the posted solution doesn't work: https://stackoverflow.com/questions/13094248/how-do-i-get-accented-letters-to-actually-work-on-bash

I'm also confident that my terminal is properly configured, as it works fine with local bash, but only the bash on a certain remote system (via ssh) has this problem.

Best Answer

You can thank someone named Lino Miguel Martins Tinoco from 2004 for this one.

The GNU Readline documentation for .inputrc does not allow in-line comments. Both it and the GNU Bourne Again shell manual say:

Lines beginning with a `#' are comments.

The line

set output-meta on     # Enable Meta output with eighth bit set
is not a line beginning with #. It's a line with a # in the middle. As Lino Miguel Martins Tinoco found, this results in the output-meta option being off, not on, as evident in the output of bind -V when xe ran it:

output-meta is set to `off'

.inputrc is not shell script. As said in the Linux From Scratch tutorial

Note that comments cannot be on the same line as commands.

Related Question