convert-meta-off

Linux命令行输入全角字符被转化

Posted onCategories技术文章

产品经理在jira里报了个ticket,说文章里有链接404了。另外非常积极主动的说,应该是没填“http://“协议头。哎,好好提你的bug,把解决bug的事情留给专业人士来不行么。人与人之间的沟通有时候就是要逞一下能,显得”我“是这个世界的主宰,在座各位都是垃圾。。。

行行行,犊子扯远了,bug还得修不是。一看这哪里是什么缺协议头。就是编辑缺了点心眼,该输入半角符号的地方,填了个全角。

href=“http (错误)
href="http (正确)

就这么个事情。目测处理起来会异常简单,

wp search-replace 'href=“http' 'href="http' --dry-run

就可以了。

本地Mac OS搞定不表,登录测试服务器Ubuntu,贴命令,特么那个全角双引号怎么不见了

查之发现,有个事情叫做readline configuration

convert-meta

If set to ‘on’, Readline will convert characters with the eighth bit set to an ASCII key sequence by stripping the eighth bit and prefixing an ESC character, converting them to a meta-prefixed key sequence. The default value is ‘on’, but will be set to ‘off’ if the locale is one that contains eight-bit characters.

大概意思是,如果这个convert meta设置开启下,带有第8个比特的字符会被转化成一个带了meta key的组合键。很显然全角字符是两个字节,所以就被转化掉了。

查看了下,我本地mac和测试机器Ubuntu,确实设置不一样。

ubuntu下
$ bind -v | grep meta
 set convert-meta on
Mac OS下
$ bind -v | grep meta
set convert-meta off

知道了问题根源,解决起来就简单多了。编辑测试机ubuntu下/etc/inputrc文件(或者新建~/.inputrc),嘿,写得清清楚楚:

# To allow the use of 8bit-characters like the german umlauts, uncomment
# the line below. However this makes the meta key not work as a meta key,
# which is annoying to those which don't need to type in 8-bit characters.

# set convert-meta off

关闭convert-meta选项的代价是meta key就不工作了。我日常工作好像不是特别依赖这个meta key,关了就关了吧。

参考:

1. https://linux.101hacks.com/unix/bind/
2. https://unix.stackexchange.com/questions/98185/bash-environment-pasting-strings-with-special-characters
3. https://www.gnu.org/software/bash/manual/html_node/Readline-Init-File-Syntax.html

发表评论

电子邮件地址不会被公开。 必填项已用*标注