GNU bug report logs - #41563
Possible bug with 'sort -Vr' version sorting

Previous Next

Package: coreutils;

Reported by: Danie de Jager <danie.dejager <at> striata.com>

Date: Wed, 27 May 2020 15:04:02 UTC

Severity: normal

Full log


View this message in rfc822 format

From: Erik Auerswald <auerswal <at> unix-ag.uni-kl.de>
To: Kamil Dudka <kdudka <at> redhat.com>
Cc: Danie de Jager <danie.dejager <at> striata.com>, 41563 <at> debbugs.gnu.org
Subject: bug#41563: Possible bug with 'sort -Vr' version sorting
Date: Thu, 28 May 2020 11:02:43 +0200
Hi,

On Thu, May 28, 2020 at 08:48:16AM +0200, Kamil Dudka wrote:
> On Wednesday, May 27, 2020 2:07:32 PM CEST Danie de Jager via GNU coreutils 
> Bug Reports wrote:
> > 
> > I use sort -Vr to sort version numbers. I noticed this discrepancy on
> > the latest kernel version from Centos 7.8.
> > 
> > command to get output:
> > # ls -t /boot/vmlinuz-* | sed "s/\/boot\/vmlinuz-//g" | grep -v rescue | sort -Vr
> > 
> > 3.10.0-1127.el7.x86_64
> > 3.10.0-1127.8.2.el7.x86_64
> > 3.10.0-1062.18.1.el7.x86_64
> 
> It is the underscore in the .x86_64 suffix what breaks the version compare 
> algorithm.  If you replace the underscore by an alphabetic character, it
> sorts as you expect:
> 
> # ls -t /boot/vmlinuz-* | sed "s/\/boot\/vmlinuz-//g" | grep -v rescue | \
>     sed 's/x86_64/x86X64/' | sort -Vr | sed 's/x86X64/x86_64/'
> 
> 3.10.0-1127.8.2.el7.x86_64
> 3.10.0-1127.el7.x86_64
> 3.10.0-1062.18.1.el7.x86_64

That is interesting.  The underscore can be replaced by a digit or even
removed as well.  Replacing it with a dot (.)  does not help.

This differs from Debian's "dpkg --compare-versions", where the results
of the comparison do not change by replacing the underscore with a
digit or character, or by removing it (the underscore is identified as
problematic, though):

    $ dpkg --compare-versions 3.10.0-1127.8.2.el7.x86_64 lt 3.10.0-1127.el7.x86_64 && echo less
    dpkg: warning: version '3.10.0-1127.8.2.el7.x86_64' has bad syntax: invalid character in revision number
    dpkg: warning: version '3.10.0-1127.el7.x86_64' has bad syntax: invalid character in revision number
    less
    $ dpkg --compare-versions 3.10.0-1127.8.2.el7.x86.64 lt 3.10.0-1127.el7.x86.64 && echo less
    less
    $ dpkg --compare-versions 3.10.0-1127.8.2.el7.x86X64 lt 3.10.0-1127.el7.x86X64 && echo less
    less
    $ dpkg --compare-versions 3.10.0-1127.8.2.el7.x86164 lt 3.10.0-1127.el7.x86164 && echo less
    less
    $ dpkg --compare-versions 3.10.0-1127.8.2.el7.x8664 lt 3.10.0-1127.el7.x8664 && echo less
    less

The way I read the GNU Coreutils documentation, removing the underscore
should not affect the version sort comparison result.

Thanks,
Erik
-- 
There is no remedy for anything in life.
                        -- Ernest Hemingway




This bug report was last modified 5 years and 25 days ago.

Previous Next


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