This situation is generally caused by not installing the Chinese language pack, or setting the default language.
View current locale
echo $LANG
Found as
zh_TW.UTF-8
However, if the Chinese language pack is not installed or enabled, garbled characters will appear
Enter LANG=en_US
and the setting is displayed in English. This command takes effect immediately, but it cannot take effect permanently. See below for permanent effect.
At this point, enter the command again and you can see the English error message
If you must need a Chinese prompt, you can install it like this:
yum groupinstall chinese-support
Set local default locale
vim /etc/locale.conf
added
LANG=“zh_TW.UTF-8”
Instant and permanent
source /etc/locale.conf
Enter locale
to view the local language environment
LANG=zh_TW.UTF-8
LC_CTYPE="zh_TW.UTF-8"
LC_NUMERIC=zh_TW.UTF-8
LC_TIME=zh_TW.UTF-8
LC_COLLATE="zh_TW.UTF-8"
LC_MONETARY=zh_TW.UTF-8
LC_MESSAGES="zh_TW.UTF-8"
LC_PAPER=zh_TW.UTF-8
LC_NAME="zh_TW.UTF-8"
LC_ADDRESS="zh_TW.UTF-8"
LC_TELEPHONE="zh_TW.UTF-8"
LC_MEASUREMENT=zh_TW.UTF-8
LC_IDENTIFICATION="zh_TW.UTF-8"
LC_ALL=
Note that my locale is Taiwan Traditional, Chinese Simplified should change TW to CN
Appendix: Let’s see how to solve the Chinese garbled code in the shell script of utf-8 encoding format in centos
Problem phenomenon
Shell script written by myself, the saved encoding format is utf-8, but uploaded to centos, it is displayed as garbled
Use file shell.sh
to view the encoding format of the file
shell.sh: UTF-8 Unicode text
Solution
Use iconv to convert the file encoding format to gb2312
iconv -f utf-8 -t gb2312 shell.sh > shell2.sh
File shell2.sh again to view the file encoding
linuxsec2.sh: ISO-8859 text
Chinese garbled problem solved
Recommended Posts