bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Sort: problem with option -f


From: Stephane CHAZELAS
Subject: Re: Sort: problem with option -f
Date: Thu, 28 Jan 2010 18:13:00 +0000 (UTC)
User-agent: slrn/pre1.0.0-16 (Linux)

2010-01-28, 09:40(-08), DennisW:
> On Jan 28, 8:43 am, Guido Milanese <guido.milan...@unicatt.it> wrote:
>> I am facing a problem concerning SORT on a Linux Ubuntu 9.04
>> distribution.
>> I noticed that the -f option seems not to work. This is an example:
>> DOG
>> CAT
>> zebra
>> dog
>> ZEBRA
>> mouse
>>
>> Running "sort" on the file I get:
>> CAT
>> dog
>> DOG
>> mouse
>> zebra
>> ZEBRA
>>
>> Running "sort -f " I get the same result. No problem of encoding, being
>> plane letters <127 -- to be sure I saved the list as 'test', and "file
>> test" says it's a pure ASCII text. Without the '-f' option, 'sort' used to
>> distinguish among lowercase / uppercase.
>> Is this a bug or a new behaviour of 'sort' ?
[...]
> This has little or nothing to do with Bash.
>
> Try this:
>
> LANG=C sort

Not guaranteed to work, in this case it's the LC_COLLATE part
that matters. The LC_COLLATE variable takes precedence over
LANG, and LC_ALL over LC_COLLATE, so:

LC_ALL=C sort

is guaranteed to work as nothing has precedence of LC_ALL.

It does have the side effect to also change the LC_MESSAGES
setting and therefore the language of sort's error messages (but
setting LANG could have that effect as well).

There's no easy work-around that.

You could do things like:

(
set -a
eval "$(locale)"
unset LC_ALL
LC_COLLATE=C
LC_CTYPE=C
exec sort file
)

You've got to have the same LC_COLLATE as LC_CTYPE otherwise the
behavior is unspecified, and if you reset LC_CTYPE, then the
error messages may be displayed in the right language, but not
the right character set. That localisation thing is not really
well designed IMO.

-- 
Stéphane


reply via email to

[Prev in Thread] Current Thread [Next in Thread]