如何让重音字母在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 03:39:22  来源:igfitidea点击:

How do I get accented letters to actually work on bash?

bashcygwinnon-ascii-characters

提问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只需执行以下操作:

  1. Go to the menu(if you don't see any menu, right click on your Terminal).
  2. Click Options....
  3. Click Text.
  4. Change the Localeto C.
  5. Change the Character setto ISO-8859-1 (Western European).
  1. 转到菜单(如果您没有看到任何菜单,请右键单击您的终端)。
  2. 点击选项...
  3. 单击文本
  4. 区域设置更改为C.
  5. 字符集更改为ISO-8859-1 (Western European).

Changing Locale and Character set in Mintty 1.1.2

在 Mintty 1.1.2 中更改语言环境和字符集

Then test it:

然后测试一下:

Echoing accented letters in Mintty 1.1.2

在 Mintty 1.1.2 中回显重音字母