bug-coreutils
[Top][All Lists]
Advanced

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

bug#22455: sort-V not sorting correctly when minor version decimal place


From: Assaf Gordon
Subject: bug#22455: sort-V not sorting correctly when minor version decimal places differ
Date: Sun, 24 Jan 2016 21:29:38 -0500

tag 22455 notabug
close 22455
thanks

Hello,

> On Jan 24, 2016, at 07:54, Vashti <address@hidden> wrote:
> [...]
> I understand that sort -V is not reliable in all cases, but this seems like
> quite a straightforward one.

"sort -V" is reliable (or at least - consistent and well defined in all cases).
It is likely that what you expect a "version string" to be is not how sort 
treats version strings. 

> $ echo -e '8.49\n8.5' | sort -V
> 8.5
> 8.49
> 
> I can produce the expected behaviour by correcting the second version
> number to two decimal places:
> 
> $ echo -e '8.49\n8.50' | sort -V
> 8.49
> 8.50
> 

First,
In gnu software versions (and in many other places), the number after the 
decimal point is not the same as a numeric decimal value.
Thus,
version "8.5" is "eight point five",
version "8.50" is "eight point fifty",
version "8.500" is "eight point five-hundred".
These are different versions, and "8.500" is the highest version number among 
them.

If you need numerical sorting, where "8.5" is equal to "8.50", then "-V" is not 
the correct sorting option (use "-n" for numeric sort).

Second,
It is incorrect to think of version numbers as decimal-point numbers (in the 
context of "sort -V").
"sort -V" follows the Debian policy regarding versions ( 
https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Version ) .
Roughly speaking, there are no decimal-point numbers (e.g. "8.5").
Instead, a version string is divided into numeric parts (all digits) and 
non-numeric parts, and each part is compared separately.

The compared parts are then:
1. "8" vs "8"
2. "." vs "."
3. "5" vs "49"

The first two parts are equal, and in the last part, value "5" comes before 
"49".
The numeric sort does not care that the non-digit character is a decimal point 
- it has no special meaning.
Just as well, it might have been a word:

   $ printf "8.49\n8.5\n" | sort -V
   8.5
   8.49

   $ printf "8foo49\n8foo5\n" | sort -V
   8foo5
   8foo49

As such, I'm making this bug as closed, but discussion can continue by replying 
to this thread.

regards,
 - assaf
 







reply via email to

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