Subject: bug#66253: closed (Re: bug#66253: sort manpage should be more explicit)

From: [email-masked] (GNU bug Tracking System)
Date: Thu, 28 Sep 2023 11:23:02 +0000

Your bug report

#66253: sort manpage should be more explicit

which was filed against the coreutils package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
66253: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=66253
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#66253: sort manpage should be more explicit
From: Pádraig Brady <[email-masked]>
To: Jorge Stolfi <[email-masked]>, [email-masked]
Date: Thu, 28 Sep 2023 12:22:35 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

On 28/09/2023 11:11, Jorge Stolfi wrote:
> The full documentation of sort explains that numeric sorting (as in
> "sort -n") accepts a leading "-" sign, decimal points, thousands
> separators, etc, but does not accept an explicit "+" sign. Values with
> explicit "+" are treated as numeric 0 and ties are broken by alpha sort.
> 
> However, the manpage only says that "-n" "compares according to string
> numerical value" -- and one would expect the numerical value of "+100"
> to be 100, not zero.
> 
> It took me an hour to figure out that my "sort -n" was failing because
> of this "feature".  Surely many users have wasted time too, or worse.
> So please either
> 
> 1) explain precisely IN THE MANPAGE what is a valid number;
> 
> 2) make numeric sort accept a leading "+", as users would expect;
> 
> 3) make numeric sort abort with an error message if any field that is
> supposed to be sorted numerically is not a valid number.
> 
> I think the best solution for users would be to implement all three of
> these...
> 
> Thank you, and all the best

Note the --debug option really helps with all this:

   $ printf '%s\n' '+4' ' 5' '-1,2.3' | sort -s -n --debug
   sort: note numbers use ‘.’ as a decimal point in this locale
   -1,2.3
   ______
   +4
   ^ no match for key
    5
    _

In saying that, sorting numbers is such a common use case,
it's probably worth adding an extra couple of lines to the man page.
I think I'll apply the following later:

   -n, --numeric-sort          compare according to string numerical value.
                                 leading blanks, negative sign, decimal point,
                                 and thousands separators are supported.

cheers,
Pádraig

Subject: sort manpage should be more explicit
From: Jorge Stolfi <[email-masked]>
To: [email-masked]
Date: Thu, 28 Sep 2023 07:11:50 -0300
List-Id: <debbugs-submit.debbugs.gnu.org>

The full documentation of sort explains that numeric sorting (as in  
"sort -n") accepts a leading "-" sign, decimal points, thousands  
separators, etc, but does not accept an explicit "+" sign. Values with  
explicit "+" are treated as numeric 0 and ties are broken by alpha sort.

However, the manpage only says that "-n" "compares according to string  
numerical value" -- and one would expect the numerical value of "+100"  
to be 100, not zero.

It took me an hour to figure out that my "sort -n" was failing because  
of this "feature".  Surely many users have wasted time too, or worse.  
So please either

1) explain precisely IN THE MANPAGE what is a valid number;

2) make numeric sort accept a leading "+", as users would expect;

3) make numeric sort abort with an error message if any field that is  
supposed to be sorted numerically is not a valid number.

I think the best solution for users would be to implement all three of  
these...

Thank you, and all the best

--jorge

-- 
Jorge Stolfi - Professor Titular/Full Professor
Instituto de Computação/Computer Science Dept
Universidade Estadual de Campinas/State University of Campinas
Campinas, SP - Brazil