Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'm writing a script in PHP that needs to compare two package version numbers to determine which is newer.

PHP has a handy function called version_compare(), but it gets really confused with some of the more creative version numbers. For example, version_compare() thinks that 0.9.8g-16ubuntu3.1 is newer than 0.9.8o-1ubuntu4.4.

Anyone know how I can get this to work?

I'm happy to run any command line scripts using exec().

share|improve this question

1 Answer 1

up vote 4 down vote accepted

take a look to the dpkg --compare-versions option, it will allow you to ask dpkg to do the comparison :)

dpkg --compare-versions 0.9.8g-16ubuntu3.1 lt 0.9.8o-1ubuntu4.4

will return 0, that means 0.9.8g-16ubuntu3.1 is lt (lesser than, < ) to 0.9.8o-1ubuntu4.4

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.