Locale oddity
Polytropon
freebsd at edvax.de
Sun Jul 19 17:57:37 UTC 2020
On Sun, 19 Jul 2020 19:14:44 +0200, Morten Bo Johansen via freebsd-questions wrote:
> 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?
There is a certain "precedence" in the language variables:
IF $LANG is set, all others are ignored; if $LC_ALL is set,
all other $LC_*s will be ignored.
You can find more information in "man 3 setlocale":
Only three locales are defined by default, the empty
string "" which denotes the native environment, and
the "C" and "POSIX" locales, which denote the C
language environment. [...] By default, C programs
start in the "C" locale.
The Handbook also has detailed information in section 22.2.
https://www.freebsd.org/doc/handbook/using-localization.html
So what you see is correct and expected: All $LC_* variables
except $LC_ALL will default to "C", otherwise they will
inherit what $LANG contains; $LC_ALL will not be set
automatically to anything.
--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
More information about the freebsd-questions
mailing list