jdm*_*jdm 7 bash readline inputrc
当我在 bash 命令行中按下某些键(例如德语变音符号)时,我会得到转义序列。例如,ß给我\303
. 这些转义序列被视为单个字符,因此一个退格键会删除整个序列。该字符只是在命令行上显示错误,但它被正确解释,例如键入echo
ß给出:
$ echo \303
ß
Run Code Online (Sandbox Code Playgroud)
我猜它有非 7 位 ASCII 字符的问题。然而,在其他所有地方,这些都可以正常工作。我可以在 vim 中使用它们或用 cat 显示它们,而且 unicode 字符也可以正常工作。
如何让 bash 正确显示这些字符?
作为记录,
TERM=xterm-256color
LANG=en_US.UTF-8
Run Code Online (Sandbox Code Playgroud)
从我的.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
Run Code Online (Sandbox Code Playgroud)
输出 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
Run Code Online (Sandbox Code Playgroud)
这个 Stackoverflow 问题显示了相同的症状,但发布的解决方案不起作用:https : //stackoverflow.com/questions/13094248/how-do-i-get-accented-letters-to-actually-work-on-bash
我也确信我的终端配置正确,因为它在本地 bash 上运行良好,但只有某个远程系统(通过 ssh)上的 bash 有这个问题。
Jde*_*eBP 10
你可以感谢2004 年的一位名叫 Lino Miguel Martins Tinoco 的人。
该用于GNU Readline库文件.inputrc
不允许行注释。它和GNU Bourne Again shell 手册都说:
以“#”开头的行是注释。
线
set output-meta on # 启用第 8 位设置的元输出是不是与开头的行
#
。这是一条#
中间有a的线。正如 Lino Miguel Martins Tinoco 发现的那样,这会导致output-meta
选项关闭,而不是打开,正如bind -V
xe 运行时的输出所示:
输出元设置为“关闭”
.inputrc
是不是shell脚本。正如Linux From Scratch 教程中所说
请注意,注释不能与命令在同一行。
好吧,我好像已经明白了。我刚刚注释掉了我的行.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
Run Code Online (Sandbox Code Playgroud)
显然在 .inputrc 中,不支持内联注释,因此所有设置都被解析为off
. 详情请参阅JdeBP 的回答。
我不知道为什么这些设置首先存在。我使用的是 Scientific Linux Cern 6.6(如 CentOS),这可能是新用户的默认设置。具有讽刺意味的是,这些设置是我系统上的默认设置(在 /etc/inputrc 中设置,但没有注释),因此它们在 .inputrc 中是不必要的,并且它们的作用与预期相反。