On Thu, 8 Nov 2001, Daniel Yacob wrote:
Is there a way to detect if the terminal that a script is running in
can display UTF-8 text?
No, not by communicating with the terminal directly. There is
neither a practical method that doesn't involve asking the user
for what she can see, nor is there a recommendable formal
standard solution.
Under Unix, you should decide in a shell script whether you can output
UTF-8 like the "nroff" script in the GNU groff package is doing it:
case "`locale charmap 2>/dev/null`" in
UTF-8)
T=-Tutf8 ;;
ISO-8859-1 | ISO8859-1)
T=-Tlatin1 ;;
IBM-1047)
T=-Tcp1047 ;;
EUC-JP)
T=-Tnippon ;;
*)
case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
*.UTF-8)
T=-Tutf8 ;;
iso_8859_1 | *.ISO-8859-1)
T=-Tlatin1 ;;
*.IBM-1047)
T=-Tcp1047 ;;
ja_JP.ujis | ja_JP.eucJP)
T=-Tnippon ;;
*)
T=-Tascii8 ;;
esac ;;
esac
This test is actually overkill, looking at the output of
'locale charmap' should be sufficient.
See also
http://www.cl.cam.ac.uk/~mgk25/unicode.html#activate
Markus
--
Markus G. Kuhn, Computer Laboratory, University of Cambridge, UK
Email: mkuhn at acm.org, WWW: <http://www.cl.cam.ac.uk/~mgk25/>