Locale oddity
Yuri Pankov
yuripv at yuripv.dev
Sun Jul 19 17:58:14 UTC 2020
Morten Bo Johansen via freebsd-questions wrote:
> Hi
>
> (This is FreeBSD 12.1-RELEASE-p7 amd64)
>
> If I unset the $LANG variable, then all other LC_* category
> locale variables will automatically be set to "C" except for
> the $LC_ALL variable:
>
> ~/ % LANG= locale
> LANG=
> LC_CTYPE="C"
> LC_COLLATE="C"
> LC_TIME="C"
> LC_NUMERIC="C"
> LC_MONETARY="C"
> LC_MESSAGES="C"
> LC_ALL=
>
> Otherwise they are:
>
> ~/ % locale
> LANG=da_DK.UTF-8
> LC_CTYPE="da_DK.UTF-8"
> LC_COLLATE="da_DK.UTF-8"
> LC_TIME="da_DK.UTF-8"
> LC_NUMERIC="da_DK.UTF-8"
> LC_MONETARY="da_DK.UTF-8"
> LC_MESSAGES="da_DK.UTF-8"
> LC_ALL=
>
> I don't understand this behaviour. Could someone explain the
> logic of this to me?
>
> To me it seems like a bug.
I'm not sure what exactly you are asking, so I'll just quote the
specification,
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html,
for the logic used:
--------
The values of locale categories shall be determined by a precedence
order; the first condition met below determines the value:
1. If the LC_ALL environment variable is defined and is not null, the
value of LC_ALL shall be used.
2. If the LC_* environment variable (LC_COLLATE, LC_CTYPE, LC_MESSAGES,
LC_MONETARY, LC_NUMERIC, LC_TIME) is defined and is not null, the value
of the environment variable shall be used to initialize the category
that corresponds to the environment variable.
3. If the LANG environment variable is defined and is not null, the
value of the LANG environment variable shall be used.
4. If the LANG environment variable is not set or is set to the empty
string, the implementation-defined default locale shall be used.
--------
Going backwards, when you unset LANG, the last rule is applied, and our
default locale is C. If you have LANG set, rule 3 is applied . Rules 1
and 2 are mostly used as overrides over the system-wide LANG setting, so
LC_* variables are NOT set by default.
More information about the freebsd-questions
mailing list