GNU bug report logs - #76290
"sort -u" vs "sort -h -u": possible bug

Previous Next

Package: coreutils;

Reported by: Rupert Gallagher <ruga <at> protonmail.com>

Date: Fri, 14 Feb 2025 17:01:01 UTC

Severity: normal

Done: Paul Eggert <eggert <at> cs.ucla.edu>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: Rupert Gallagher <ruga <at> protonmail.com>
To: "eggert <at> cs.ucla.edu" <eggert <at> cs.ucla.edu>
Cc: "76290 <at> debbugs.gnu.org" <76290 <at> debbugs.gnu.org>
Subject: bug#76290: "sort -u" vs "sort -h -u": possible bug
Date: Sun, 16 Feb 2025 11:02:37 +0000
My concern is best described as follows.

~ $ echo -e "CVE-2018-13787\nCVE-2019-16649\nCVE-2019-16650\nCVE-2020-15046\nCVE-2018-13787" | sort -h
CVE-2018-13787
CVE-2018-13787
CVE-2019-16649
CVE-2019-16650
CVE-2020-15046

~ $ echo -e "CVE-2018-13787\nCVE-2019-16649\nCVE-2019-16650\nCVE-2020-15046\nCVE-2018-13787" | sort -h -u
CVE-2018-13787

The introduction of the unique operator (-u) returns a wrong answer when used with the human sorting operator (-h).

Note the problem does not occur when the human sorting operator is not used.

~ $ echo -e "CVE-2018-13787\nCVE-2019-16649\nCVE-2019-16650\nCVE-2020-15046\nCVE-2018-13787" | sort
CVE-2018-13787
CVE-2018-13787
CVE-2019-16649
CVE-2019-16650
CVE-2020-15046

~ $ echo -e "CVE-2018-13787\nCVE-2019-16649\nCVE-2019-16650\nCVE-2020-15046\nCVE-2018-13787" | sort -u
CVE-2018-13787
CVE-2019-16649
CVE-2019-16650
CVE-2020-15046

The example suggests the existence of a programming error between the output of -h and the input of -u.


-------- Original Message --------
On 2/16/25 07:23, Paul Eggert wrote:

>  I don't see a bug there, just an infelicity. -h means 'sort' should look for a number, and your data lines don't start with numbers.
>  
>  Try 'sort --debug -h -u' to see more.
>




This bug report was last modified 92 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.