Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Scripting and LANG=C

0 views
Skip to first unread message

Robbo

unread,
Jan 28, 2009, 12:58:39 PM1/28/09
to
Hello,

We all know, that locale would be
a problem when scripting in e.g. bash.
For example, when LC_COLLATE
is not set to "C", echo [a-z] could also
show filenames like "A", "B" (not only
lowecase).
All (or almost all) materials I have read
have told that it is usefull to set "LANG=C"
when scripting.
My questing is, why to set LANG=C,
not other variables?
Maybe it is better to set LC_ALL=C
(LC_ALL has "higher priority" than LANG)
or LC_COLLATE (LC_COLLATE has
also "higher priority" than LANG)?

Thanks in advance for your answer.

Regards,
Robbo


Ignoramus2885

unread,
Jan 28, 2009, 3:49:28 PM1/28/09
to
When you find out, let me know, this shit is really scary.

I had some scripts that would check if day of the week is a certain
day like Sunday, and they did not work on a computer who was set to
use Russian language.

i

--
Due to extreme spam originating from Google Groups, and their inattention
to spammers, I and many others block all articles originating
from Google Groups. If you want your postings to be seen by
more readers you will need to find a different means of
posting on Usenet.
http://improve-usenet.org/

Sidney Lambe

unread,
Jan 28, 2009, 4:55:58 PM1/28/09
to

The folks on comp.unix.shell are much more
likely to be able to give you an answer here.

Sid

Sven Mascheck

unread,
Jan 29, 2009, 4:50:06 AM1/29/09
to
> Robbo wrote:

>> All (or almost all) materials I have read
>> have told that it is usefull to set "LANG=C"
>> when scripting.
>> My questing is, why to set LANG=C,
>> not other variables?
>> Maybe it is better to set LC_ALL=C
>> (LC_ALL has "higher priority" than LANG)
>> or LC_COLLATE (LC_COLLATE has
>> also "higher priority" than LANG)?

Yes, the priorities decrease from LC_ALL over LC_* to LANG.

But you should set LC_ALL only for debugging or in severe cases,
because you can't make use of any of the individual categories
anymore (for example LC_CTYPE for special characters).

You are right: If LC_COLLATE is explicitly set, LANG won't help.
You certainly could override it with LC_ALL, but you should
simply adjust LC_COLLATE itself.

There is a rarely documented feature, which helps finding
(and adjusting) the very settings immediately: implicit
assignments are denoted with quotes.

In the following, only LANG and LC_CTYPE are set explicitly.
All other categories follow the setting of LANG and thus their
values are quoted:

$ locale
LANG=en_US
LC_CTYPE=en_US
LC_NUMERIC="en_US"
LC_TIME="en_US"
LC_COLLATE="en_US"
LC_MONETARY="en_US"
LC_MESSAGES="en_US"
LC_ALL=

[not linux specific: followups redirected to comp.unix.shell]

Bill Marcum

unread,
Jan 30, 2009, 8:05:59 AM1/30/09
to
On 2009-01-28, Ignoramus2885 <ignora...@NOSPAM.2885.invalid> wrote:
>
>
> When you find out, let me know, this shit is really scary.
>
> I had some scripts that would check if day of the week is a certain
> day like Sunday, and they did not work on a computer who was set to
> use Russian language.
>
date +%w gives the day of the week as a number from 0 to 6 (Sunday is 0).


--
Isn't it conceivable to you that an intelligent person could harbor
two opposing ideas in his mind?
-- Adlai Stevenson, to reporters

0 new messages