Bug 64226 - Sort creates wrong order if sorting multiple fields
Sort creates wrong order if sorting multiple fields
Product: Red Hat Linux
Classification: Retired
Component: textutils (Show other bugs)
All Linux
medium Severity medium
: ---
: ---
Assigned To: Tim Waugh
Ben Levenson
Depends On:
  Show dependency treegraph
Reported: 2002-04-29 14:50 EDT by Fedor Pikus
Modified: 2007-04-18 12:42 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-09-25 22:03:24 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Fedor Pikus 2002-04-29 14:50:11 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 Galeon/1.2.0 (X11; Linux i686; U;) Gecko/20020311

Description of problem:
Rus this:
( echo '/  e' ; echo '/b e' ) | sort
/b e
/  e

Now run this:
( echo '/  e' ; echo '/b e' ) | sort -k 1,1
/  e
/b e

I think the first one is wrong: sort should look at the first field, then second
field if needed. In this case second field is not needed, first field "/" should
go before "/b" and that's enough for sorting.
Instead, sort somehow merges the fields and sorts on the "b before e" order: if
I say instead
 ( echo '/  a' ; echo '/b a' ) | sort
then the order is correct,
/  a
/b a
but for the wrong reason, it sorts this way because "a before b", should be
because "/ before /b".

Here is where the problem comes out: autofs4 creates /net mounts by
sorting output of showmount. Typical output looks something like this:
/    (everyone)
/a   (everyone)
Since a < e, sorted order is /a first. autofs4 creates a strange infinite loop
of mounts when /a is mounted before /.

Version-Release number of selected component (if applicable):
rpm -q textutils

How reproducible:

Steps to Reproduce:
1.( echo '/  e' ; echo '/b e' ) | sort - BAD
2.( echo '/  e' ; echo '/a e' ) | sort -k 1,1 - GOOD

Additional info:
Comment 1 Bill Hees 2002-08-07 17:37:13 EDT
This 'multiple fields' bug is likely caused by the fact that if LC_COLLATE is
undefined (and that's the default configuration it seems) sort ignores spaces. 
This came up in bug 17204 too.

I've found 'default' sort also ignores hyphens.  The following text is
considered sorted:

x 30
x -4
x 50

Seems pretty wrong IMO.  I couldn't find a Posix spec for what should happen
when LC_COLLATE is undefined.  If it's up to the implementer it would seem
defaulting to C-style would be safer than the current approach.

-Bill Hees
Comment 2 Tim Waugh 2002-10-07 07:23:19 EDT
'Undefined'?  What exactly is LC_COLLATE in your example?  Not C, I'll be 

Note You need to log in before you can comment on or make changes to this bug.