[PATCH] fix version comparison

Matt Domsch Matt_Domsch at dell.com
Fri Apr 14 13:33:03 CDT 2006


On Fri, Apr 14, 2006 at 01:20:12PM -0500, Michael_E_Brown at dell.com wrote:
> Only one comment: Any way to get something more robust than an ASCII
> sort version comparison?

This is the function that lets the ASCII sort version comparison
work.  IIRC, this was suggested by developers at SuSE.

function VER()
{
    # $1 = kernel version string

    # Pad all numbers in $1 so that they have at least three digits, e.g.,
    #   2.6.9-1cvs200409091247 => 002.006.009-001cvs200409091247
    # The result should compare correctly as a string.

    echo $1 | sed -e 's:\([^0-9]\)\([0-9]\):\1 \2:g' \
                  -e 's:\([0-9]\)\([^0-9]\):\1 \2:g' \
                  -e 's:\(.*\): \1 :' \
                  -e 's: \([0-9]\) : 00\1 :g' \
                  -e 's: \([0-9][0-9]\) : 0\1 :g' \
                  -e 's: ::g'
}



However, you do raise a good point: there needs to be added to this an
initial -e 's:^v::'    to delete the letter 'v' from stupid version
strings (like older ipmi drivers had, 'v35.0' which doesn't compare
well with '36.0').

-- 
Matt Domsch
Software Architect
Dell Linux Solutions linux.dell.com & www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com



More information about the DKMS-devel mailing list