The duplication in /etc/profile is specifically for ... what?
What else relies on /etc/profile?
/etc/profile is read by
bourne shells when executed as a login shell. A session started by a display manager will typically be a bourne shell script, so
/etc/profile is sourced and a good place to set some environment. Of course, if your user's shell is a bourne shell, you will have
LANG
set twice for a console login, but this doesn't hurt.
That :charset entry is happily copied along by everybody commenting on the issue, while it actually is just bogus, i.e. nothing seems to use it.
Maybe you're right on this, still it is used even in the example
russian
class in
/etc/login.conf, so I just assume there is
some software using it.
what is set by the login.conf :charset entry is an MM_CHARSET variable
Indeed, I didn't read the manpage properly here.
I do not know if a construct like C.UTF-8 is in any way legal.
I don't either, but that was asked about. Still if such a thing is legal, it makes some sense: Use a "neutral" locale, but with UTF-8 charset (while your suggested
en_US.UTF-8
will use US-american date formats and so on).
Setting LANG (or in login.conf :lang) has some side-effects which you may or may not want [...]
I'd say that's
exactly what you want. But admittedly,
LANG
is a misnomer here, suggesting it would
only set the language.
In order to avoid these, i.e. leave them in the default american mode which less likely breaks compatibilities, [...]
Of course, any correctly written script relying on exact reproducible output of some tools should always set
LANG=C
in its environment.
Therefore all daemons and server applications are by default using just bytes ( LANG=C), and if they want something different, they have to care by themselves for that.
I'd say that's only half true, all it takes using the standard C library is
setlocale(LC_ALL, "")
and some functions start to behave locale-specific (e.g. in
ctype.h
).
And if you set it in /etc/profile, you need to think through whether it needs to be in the section only for interactive logins. Do you really want to use this for non-interactive logins, commands coming in via ssh, batch, cron jobs? Maybe you do, maybe you don't.
AFAIK,
/etc/profile should only be considered by login shells.