Bug 104511

Summary: Add “locale -c charmap” as an example to locale(1)
Product: Documentation Reporter: Florian Weimer (fweimer)
Component: man-pagesAssignee: documentation_man-pages (documentation_man-pages)
Status: RESOLVED CODE_FIX    
Severity: enhancement CC: mtk.manpages, myllynen
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: Subsystem:
Regression: No Bisected commit-id:

Description Florian Weimer 2015-09-14 09:41:25 UTC
This prints “LC_CTYPE” followed by the name of the charset.  This is often quite useful information, and there does not seem to be another convenient way to get this information from the shell.  It's also not apparent how to get this information from locale(1).
Comment 1 Marko Myllynen 2016-01-18 08:09:58 UTC
Hi Florian,

The first example is:

       $ locale
       LANG=en_US.UTF-8
       LC_CTYPE="en_US.UTF-8"
       ...

And there the encoding listed matches the charset in use, do you think an additional example would still be warranted?

http://man7.org/linux/man-pages/man1/locale.1.html

Thanks.
Comment 2 Florian Weimer 2016-01-18 10:42:32 UTC
(In reply to Marko Myllynen from comment #1)
> Hi Florian,
> 
> The first example is:
> 
>        $ locale
>        LANG=en_US.UTF-8
>        LC_CTYPE="en_US.UTF-8"
>        ...
> 
> And there the encoding listed matches the charset in use, do you think an
> additional example would still be warranted?

Yes, absolutely, because “locale -c charmap” works even if the charset is not part of the locale name:

$ LC_ALL=zh_CN locale -c charmap 
LC_CTYPE
GB2312
$ LC_ALL=lzh_TW locale -c charmap 
LC_CTYPE
UTF-8
$ LC_ALL=zh_HK locale -c charmap 
LC_CTYPE
BIG5-HKSCS

I don't know of any other convenient way to obtain this information (short of writing a small C program which uses nl_langinfo(CODESET)).
Comment 3 Marko Myllynen 2016-01-18 10:57:27 UTC
Patch posted at http://thread.gmane.org/gmane.linux.man/10064. Thanks.
Comment 4 Michael Kerrisk 2016-03-11 19:05:54 UTC
Closing this, as that patch was merged.