Strange characters from output in shell
6,640
Solution 1
Either use a terminal program that understands UTF-8, or tell your shell to not use UTF-8 via $LANG
.
>>> print u'°'.encode('utf-8').decode('latin-1')
°
Solution 2
You should set your locale to C:
export LC_ALL=C
Author by
Aaron
Passionate software engineer with strong knowledge and experience in Linux, security, and databases.
Updated on September 18, 2022Comments
-
Aaron over 1 year
Over the past few years there have been some Linux systems that will output strange characters when running various commands. Here's an example of my output from the
sensors
command on one of those machines:acpitz-virtual-0 Adapter: Virtual device temp1: +45.5°C (crit = +126.0°C) coretemp-isa-0000 Adapter: ISA adapter Core 0: +44.0°C (high = +100.0°C, crit = +100.0°C) Core 1: +45.0°C (high = +100.0°C, crit = +100.0°C) nouveau-pci-0100 Adapter: PCI adapter temp1: -62.0°C (high = +95.0°C, crit = +99.0°C)
Notice the
Â
character all over the place. Why does this happen in some environments and not others? What can I do to correct this? -
Aaron over 10 yearsThanks, I realized I hadn't set this up in Putty on Windows. That is where the problem was happening, not when using the terminal in various Linux distros. My mistake!
-
Ignacio Vazquez-Abrams over 10 yearsIn this case PuTTY would be your terminal program.
-
Philip Kearns over 7 yearsIn my case I was seeing strange characters when logging in from Solaris 10 to Linux. I did
export LC_ALL=en_IE.UTF-8
on the Linux host and set the Solaris terminal character encoding to UTF-8. It was fine after that.