Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there anyway for a bash (or any other shell) script to detect whether the current terminal supports unicode characters?

I'd like to use Unicode characters if they are supported by the terminal, and fall back to ASCII characters if the user's terminal can't display them correctly. Is there any relatively easy way to do this in a shell script?

like image 817
iconoclast Avatar asked Feb 12 '11 07:02

iconoclast


1 Answers

First, you're probably confusing Unicode with a particular encoding. Suppose you know that the termnal supports Unicode characters -- you still don't know how to print them!

You're probably thinking about something like UTF-8, the most popular Unicode encoding out there.

To get the encoding of the current locale, use

locale charmap

This is the encoding of the current locale, and theoretically it may differ from the encoding used by the terminal, but in that case something is broken on user's side.

like image 159
Roman Cheplyaka Avatar answered Oct 17 '22 14:10

Roman Cheplyaka