How do I use the extended ASCII character set in the text console in Red Hat Enterprise Linux 5?
Issue
- The Extended ASCII character set does not render correctly on the text console in Red Hat Enterprise Linux 5. The reason for this is that Red Hat Enterprise Linux 5 uses unicode to display text by default. Due to this, the extended ASCII characters are either incorrectly rendered or not rendered at all.
Environment
- Red Hat Enterprise Linux(RHEL) 5
Solution
To be able to see these extended characters on text console, one must disable unicode support for the console and switch character encoding to CP437. It can be done by running the following commands as root:
root@localhost# unicode_stop
root@localhost# setfont default8x16
root@localhost# setfont -m cp437
Note
The extended ASCII character set was used to display window borders and other non-ASCII artifacts in legacy console applications. There is however, no formal standard around it, due to which it should be considered deprecated in favour of standard character sets such as UTF-8. It is hence recommended that application developers avoid use of this character set and instead use UTF-8. One could get the UTF-8 equivalent of a character in an extended ASCII character set in the following manner:
1) Dump the desired character(s) into a file:
foo@localhost$ printf "\303\n" > mychar.txt
2) Convert the file using iconv:
foo@localhost$ iconv -f CP437 -t UTF-8 -o mychar-utf8.txt mychar.txt
3) Get the octal dump of the converted file to get octal code for the UTF-8 equivalent:
foo@localhost$ od -c mychar-utf8.txt
Note that the output UTF-8 character code may span across multiple bytes, so one should cater for multibyte characters in their application when using UTF-8. To do this conveniently and in a cross-platform manner, one may use Unicode string handling functions in the GNU glib2 library.
Subscriber exclusive content
A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.