Red Hat Bugzilla – Bug 17749
sort generating incorrect sort order
Last modified: 2008-05-01 11:37:58 EDT
Using sort on my newsgroups generates the following order.
(co.politics shouldn't be at the end):
It's actually a feature (locale sorting).
whatever | LC_COLLATE="C" sort
to get the old behavior.
Setting $LANG causes the behaviour to change. For example:
% echo -e "a\nB" | LANG= sort
% echo -e "a\nB" | LANG=en sort
% echo -e "a\nB" | LANG=en_US sort
Why should 'en' and 'en_US' be different? (The same problem applies to en_GB,
en_AU; fr is okay but fr_FR is broken...)
There are a huge number of shell scripts, Makefiles and other programs out there
that expect sort to sort case-sensitively and in ASCII order. They probably
don't expect that the sort order will change due to random environment
variables. So I'd say that the default should be to keep the traditional sort
order (at least when the input data is ASCII) unless the user specifically asks
for something else.
The reason why 'en' is different to 'en_US' is that while the stuff in
/usr/share/locale/ is part of glibc, locale/en/ is generated by the package
'kpilot'! I'm not sure why kpilot feels it needs a locale all to itself, but
the package probably needs fixing. Similarly, some KDE packages have generated
an en_UK/ directory when the correct name should be en_GB/. This is probably a
bug in KDE.
BTW, I strongly disagree with the resolution 'NOTABUG'. Breaking the behaviour
of sort(1) is about as close to a major bug as you can get. Although I realize
that POSIX mandates the brokenness. The sheer number of bug reports submitted
about this should be an indication that sort is not doing the Right Thing.
The manual page could be a lot clearer about what is going on - it mentions
$LC_COLLATE but not $LANG. Other things in the manual page like '-f fold lower
case to upper case' are also misleading if the sort order has already been
modified by a locale.
Let's add a worse effect caused by the same default:
using a locale-aware shell (such as bash 2), what happens with
1) "en_US" locale settings:
Removes every file whose name starts with a letter, except if the letter is a lowcase z.
2) "C" locale settings:
Removes every file whose name starts with a capital letter.
Yes, this still works as documented, but choosing default environment that works
this much differently from what has been considered "normal behaviour" should
have a big warning sticker taped on a visible place.