bug-coreutils
[Top][All Lists]
Advanced

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

Re: The comparison function of Linux sort command


From: Eric Blake
Subject: Re: The comparison function of Linux sort command
Date: Tue, 26 Jun 2007 19:04:42 -0600
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.12) Gecko/20070509 Thunderbird/1.5.0.12 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Lei Guo on 6/26/2007 6:58 PM:
> For string comparison, it seems Linux sort assume number < lowercase <
> uppercase. However, the ASCII value is: number < uppercase < lowercase.
> Thus, the comparison function of Linux sort is different from that of C
> function strcmp(). Is this a bug, or it is designed in this way for some
> purpose?

It is a feature of your locale:
http://www.gnu.org/software/coreutils/faq/coreutils-faq.html#Sort-does-not-sort-in-normal-order_0021

This is due to the fact that you or your vendor have set environment
variables that direct the program to use locale specific sorting tables
which do not sort as you expect. You or your vendor have probably set
environment variables like LANG, LC_ALL, or LANG to en_US. There appears
to be a problem with that table on some systems which is not part of the
GNU program but part of your vendor's system release.

Unset them, and then set LC_ALL to POSIX.

       # If you use bash or some other Bourne-based shell,
       export LC_ALL=POSIX

       # If you use a C-shell,
       setenv LC_ALL POSIX

and it will then work the way you expect because it will use a different
set of tables.

> sort --version
> sort (coreutils) 5.2.1

This is a rather old version.  I would recommend upgrading to the latest
stable version, 6.9.

> sort - GNU textutils 1.14

And this is even more ancient.  Double the upgrade advice.

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGgbeq84KuGfSFAYARAk4MAKDEckRUHCH2fs0um2gEpV1/fCq1kgCeNKeF
j/ZZZ7ymVr/zBfKFYGTdvHY=
=w+iU
-----END PGP SIGNATURE-----




reply via email to

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