6

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.

  • What does echo $LANG show? – dr01 May 4 '15 at 9:03
  • What is the result of stty -a ? – Archemar May 4 '15 at 9:04
  • @jdm; You solved your issue, I see. But (for the record) I want to point out that (e.g.) ksh does not have that problem. In ksh there's also no need to fiddle with stty or locale settings, so I assume the functions behind those hints are not the cause of the observed bash issue. – Janis May 4 '15 at 10:17
10

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.

  • Thanks! Wow, this is ridiculous. set output-meta on # comment turns it off, while omitting or commenting out the line turns it on (as it is the default in /etc/inputrc). – jdm May 4 '15 at 11:04
1

OK, I seem to have figured it out. I just commented out the lines in my .inputrc and it works:

#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

Apparently in .inputrc, inline comments are not supported, so all settings are parsed as off. See the answer from JdeBP for details.

I don't know why these settings were there in the first place. I'm on Scientific Linux Cern 6.6 (like CentOS), and this was presumely the default for new users. The ironic thing is that these settings are the default on my system (set in /etc/inputrc, but without comments), so they are unnceccessary in .inputrc, and they do the opposite of what is intended.

  • Glad you found a solution, I usually solve this (in redhat and ubuntu) in putty's setup (playing with UTF-8). – Archemar May 4 '15 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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