Difference between revisions of "Weird Characters in Terminal"

From TheBeard Science Project Wiki
Jump to: navigation, search
Line 22: Line 22:
  
 
</source>
 
</source>
 +
<i>May also be something like "â".</i>
  
 
Use the <code>locale</code> command to view the language and encoding scheme environment variables:
 
Use the <code>locale</code> command to view the language and encoding scheme environment variables:

Revision as of 00:37, 14 January 2020

Sometimes there is a mismatch between the system locale and the terminal's encoding scheme. The example below is using Ubuntu Server 18.04 and PuTTY.

You can see some characters display oddly:

neuro@neuromancer:~/Documents$ tree -L 1
.
βββ Books
βββ Business
βββ Code
βββ Datasheets
βββ Financial
βββ Game Stuff
βββ Labels
βββ Network
βββ Personal Documents
βββ Receipts
βββ Schematics
βββ Technical
βββ Web Documents
βββ Work

May also be something like "â".

Use the locale command to view the language and encoding scheme environment variables:

neuro@neuromancer:~$ locale
LANG=
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

You can see that the variables LANG, LANGUAGE, and LC_ALL are not set. You can set them temporarily like this (assuming you want US English and UTF-8):

export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Put these export commands at the end of your ~/.bashrc file to set these variables on login for your user account only.

To make these permanent system-wide, edit the file /etc/default/locale and enter these lines:

LANG=en_US.UTF-8
LANGUAGE=en_US.UTF-8
LC_ALL=en_US.UTF-8

Log out and log in again for these defaults to take effect.

In some situations, you might need to do these commands:

sudo locale-gen en_US en_US.UTF-8
sudo dpkg-reconfigure locales

Now, make sure the character encoding in your terminal emulator is set to UTF-8. In PuTTY, right-click the window frame and click "Change Settings...".

Under Window > Translation, set the "Remote character set" to "UTF-8". I also set the radio button "Use Unicode line drawing code points".

Putty1.png

Then Under "Session", Click "Default Settings" and click "Save".

Now click "Apply" at the bottom of the window.

The character display should now be fixed:

neuro@neuromancer:~/Documents$ tree -L 1
.
├── Books
├── Business
├── Code
├── Datasheets
├── Financial
├── Game Stuff
├── Labels
├── Network
├── Personal Documents
├── Receipts
├── Schematics
├── Technical
├── Web Documents
└── Work

14 directories, 0 files