[Top][All Lists]

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

bug#30661: sort

From: Eric Blake
Subject: bug#30661: sort
Date: Thu, 1 Mar 2018 10:15:36 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0

tag 30661 notabug

On 02/28/2018 05:42 PM, James Bunke wrote:
To: address@hidden

This seems an oversight than an actual bug:

     'sort -n' thinks "B" is a larger value than "AA" -- yep! someone
forgot about hexadecimal, but binary, octal, and decimal work fine.

Please demonstrate an actual command line that you typed and output you got. Here's what I tried in reproducing your claim:

$ printf 'AA\nB\n' | LC_ALL=C sort --debug -n
sort: using simple byte comparison
^ no match for key
^ no match for key

As I typed it, 'sort -n' outputs the line AA before the line B because of fallback sorting rules (the entire line is used when none of the keys produced a difference, and since neither line was numeric, they were equivalently treated as '0' by -n), contrary to your claim that sort takes 'B' first. Therefore, I don't know if my attempt matches what you actually saw, as you did not give very many details other than a vague verbal description of your issue.

Suggestion: Don't revert to alphanumeric sorting until the rules are
broken by the sort field:

Sorry, but 'sort -n' behavior is specified by POSIX, and we can't change it, as that would break scripts that expect POSIX behavior. Most likely, sort can already do what you want with additional command line options, but I don't even know what data you want sorted, or what output you actually want, to tell you what command line would give the output you want. The --debug option can be great at learning what sort is actually doing (and how it is more likely that your request is incomplete, rather than sort misbehaving).

As such, I'm closing this as not a bug, as you have not demonstrated an actual POSIX compliance issue; but do feel free to provide us with more information, and we can reopen this if you actually do come up with something that needs addressing beyond what sort can already do when invoked correctly.

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

reply via email to

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