CentOS8 - bash: garbled characters and solutions

CentOS8 - bash: garbled characters and solutions

This situation usually occurs because the Chinese language pack is not installed or there is a problem with the default language setting.
View the current locale
echo $LANG
Found to be
zh_TW.UTF-8
However, if the Chinese language pack is not installed or enabled, garbled characters will appear.

Enter LANG=en_US to set the display to English. This command takes effect immediately but not permanently. See below for permanent effect.
At this point, enter the command again to see the English error message

If you really need Chinese prompts, you can install it like this:
yum groupinstall chinese-support
Set the local default locale
vim /etc/locale.conf add
LANG="zh_TW.UTF-8"
Immediate and permanent effect
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 language environment is Taiwan Traditional Chinese, and the simplified Chinese language should be changed from TW to CN

Appendix: Let's take a look at the solution to Chinese garbled characters in the shell script that displays utf-8 encoding format in centos

Problem phenomenon

The shell script I wrote was saved in utf-8 encoding format, but when uploaded to centos, it was displayed as garbled characters

Use file shell.sh to view the encoding format of the file

shell.sh: UTF-8 Unicode text

Workaround

Use iconv to convert the file encoding format to gb2312

iconv -f utf-8 -t gb2312 shell.sh > shell2.sh

Run file shell2.sh again to view the file encoding

linuxsec2.sh: ISO-8859 text

The Chinese garbled characters problem has been solved

This is the end of this article about the CentOS8-bash: garbled code problem. For more related centos bash garbled code content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

<<:  Example analysis of the principle and solution of MySQL sliding order problem

>>:  jQuery implements HTML element hiding and display

Recommend

A practical record of encountering XSS attack in a VUE project

Table of contents Preface Discover the cause Cust...

Vite2.0 Pitfalls

Table of contents Vite project build optimization...

Create a custom system tray indicator for your tasks on Linux

System tray icons are still a magical feature tod...

Detailed explanation of three ways to import CSS files

There are three ways to introduce CSS: inline sty...

Detailed explanation of pure SQL statement method based on JPQL

JPQL stands for Java Persistence Query Language. ...

Basic notes on html and css (must read for front-end)

When I first came into contact with HTML, I alway...

js method to realize shopping cart calculation

This article example shares the specific code of ...

A very detailed tutorial on installing rocketmq under Docker Desktop

Install Docker Desktop Download address: Docker D...

React dva implementation code

Table of contents dva Using dva Implementing DVA ...

JavaScript mobile H5 image generation solution explanation

Now there are many WeChat public account operatio...

javascript realizes 10-second countdown for payment

This article shares the specific code of javascri...

Some key points of website visual design

From handicraft design to graphic design to web de...