如何让重音字母在 bash 上实际工作?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 
原文地址: http://stackoverflow.com/questions/13094248/
Warning: these are provided under cc-by-sa 4.0 license.  You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I get accented letters to actually work on bash?
提问by Ferdinando Randisi
My bash installation on cygwin doesn't handle accented letters properly. I tried adding
我在 cygwin 上的 bash 安装无法正确处理重音字母。我尝试添加
set input-meta on    # to accept 8-bit characters
set output-meta on   # to show 8-bit characters
set convert-meta on  # to show it as character, not the octal representation
to my input rc, but this doesn't quite work yet. Indeed, if I type
到我的输入 rc,但这还不太奏效。事实上,如果我输入
$ echo ù
then before i press enter it is automatically changed to
然后在我按下回车键之前它会自动更改为
$ echo 3
although the output is right, for I get
虽然输出是正确的,因为我得到
$ echo 3
ù
I get the same result for anyother accented letter. Usually though I use a non-italian keyboard, and I use autohotkeyto substitute letters with an apostrophe after them with an accented letter. When this is the case, accented letters get substituted with a \302, and they print garbage depending on the letter: prints a 3yfor a ù, a ¢for an ò, and nothing for everething else.
对于任何其他重音字母,我得到相同的结果。通常,尽管我使用非意大利语键盘,但我autohotkey习惯于用重音字母替换字母后用撇号代替字母。在这种情况下,重音字母会被替换为 a \302,并且它们会根据字母打印垃圾:3y为 a打印a ù,¢为 an打印 a ò,而其他什么都不打印。
How do I get all this to make sense?
我如何让这一切有意义?
EDIT: my locale settings, cygwin version and terminal are the following
编辑:我的语言环境设置、cygwin 版本和终端如下
$ uname -a
CYGWIN_NT-6.1-WOW64 ferdi-Asus 1.7.17(0.262/5/3) 2012-10-19 14:39 i686 Cygwin
$ locale
LANG=it_IT.UTF-8
LC_CTYPE="it_IT.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="it_IT.UTF-8"
LC_COLLATE="it_IT.UTF-8"
LC_MONETARY="it_IT.UTF-8"
LC_MESSAGES="it_IT.UTF-8"
LC_ALL=
$ tty
/dev/pty1
I'm invoking it simply clicking the Cygwin terminal link. It redirects to
我只需单击 Cygwin 终端链接即可调用它。它重定向到
C:\cygwin\bin\mintty.exe -i /Cygwin-Terminal.ico -
The relevant part of the autohotkey script is the following
autohotkey 脚本的相关部分如下
#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
...
::avra'::avrà
::avro'::avrò
...
采纳答案by Rubens Mariuzzo
To get accented letters on bash via Cygwinusing Mintty 1.1.2just do the following:
要通过Cygwin使用在 bash 上获得重音字母,Mintty 1.1.2只需执行以下操作:
- Go to the menu(if you don't see any menu, right click on your Terminal).
- Click Options....
- Click Text.
- Change the Localeto C.
- Change the Character setto ISO-8859-1 (Western European).
- 转到菜单(如果您没有看到任何菜单,请右键单击您的终端)。
- 点击选项...。
- 单击文本。
- 将区域设置更改为C.
- 将字符集更改为ISO-8859-1 (Western European).


Then test it:
然后测试一下:



