On Thu, 17 Jun 2004, Enrique Perez-Terron wrote: > What is the proper way of comparing versions of rpms in a bash script? > > This is actually two questions, what is the proper order, and what is > the simplest way of implementing that order. > > To the first part, is this right? > 4.01-3 > 4.01-3p # letter suffixes sort like strings > 4.01-3q > 4.1-3p # leading zeros before no leading zero > 4.2 > 4.10 # otherwise numeric part sort as numbers > 4.10-4 > 4.10.3-1 # components separated with dots are "more important" than > the dash, i.e. 4.10-4 is a "smaller variation" of 4.10 than 4.10.3 > > I think I have seen versions with letter prefixes too. How do they sort? > You can take this advice or leave it, but my thoughts are that you should create a little script/program written in either Perl, Python or C that asks librpm about the version. Here is a short example in Perl using the RPM2 perl bindings for rpm: #!/usr/bin/perl use RPM2; my $v1 = shift; my $v2 = shift; exit(RPM2::rpmvercmp($v1, $v2) + 1); rpmvercmp() returns: -1 $v1 < $v2 0 $v1 = $v2 1 $v1 > $v2 exit codes must be zero or positive so I increment the result by one. This bit of code can be wrapped in a shell subroutine in an inline perl script useing the -e option if you like. You can do the same thing in C or Python. The end result though, is that your version comparison will always agree with rpm because you are asking rpm (rpmvercmp is actually subroutine in librpm that rpm uses when doing version comparisons). If you can search back through the archive, you will find about a year ago where I actually mapped out from the reading the source how rpm does version comparisons, but in short it splits things up into numeric and non-numeric components and then compares each component in the parallel lists (note, its not quite that simple in the source, but you would get the same results, also there are special case for when corresponding components are not both numeric or alpha). > ( <rant> > And why the heck do people invent such versions strings!! > </rant> ) They can get much nastier than that (-; The bottom line is that if your code disagrees with rpm unless you throw --force your wrong, so its best to ask rpm about these matters. Cheers...james > > Regards, > Enrique > > > > _______________________________________________ > Rpm-list mailing list > Rpm-list@xxxxxxxxxx > https://www.redhat.com/mailman/listinfo/rpm-list > _______________________________________________ Rpm-list mailing list Rpm-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/rpm-list