bash 为什么我的终端不能正确输出 unicode 字符?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12649896/
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-09 22:45:57  来源:igfitidea点击:

Why doesn't my terminal output unicode characters properly?

bashshellcommand-lineconsoleterminal

提问by trusktr

For example, my terminal does this:

例如,我的终端是这样做的:

$ echo -e "\xE2\x98\xA0"
???

I expect it to do this:

我希望它这样做:

$ echo -e "\xE2\x98\xA0"
?

Why? How do I make my terminal output the proper unicode symbols?

为什么?如何让我的终端输出正确的 unicode 符号?

I'm using Gnome 3's Terminal on Arch Linux.

我在 Arch Linux 上使用 Gnome 3 的终端。

The output of localeshows:

显示输出locale

LANG=C
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=

回答by trusktr

I figured it out. I had to make sure I set LANGUAGE="en_US.UTF-8"in /etc/rc.confand LANG="en_US.UTF-8"in /etc/locale.conf, then logged out and logged back in and it worked. My terminal displays unicode properly now.

我想到了。我必须确保我LANGUAGE="en_US.UTF-8"进入/etc/rc.confLANG="en_US.UTF-8"进入/etc/locale.conf,然后注销并重新登录并且它工作。我的终端现在可以正确显示 unicode。

回答by Nimlar

In case you cannot change /etc/*files, you can manually set the gnome-terminalmenu Terminal|Set Character Encodingto Unicode(Utf-8)

如果您无法更改/etc/*文件,您可以手动设置gnome-terminal菜单Terminal| Set Character EncodingUnicode(Utf-8)

回答by Ben

I updated my locale with the following command:

我使用以下命令更新了我的语言环境:

sudo update-locale LANG=en_US.UTF-8 LANGUAGE=en.UTF-8

then rebooted:

然后重新启动:

sudo reboot