wpkg --compare-versions

Options Comments
--verbose When the --verbose is used and the versions are valid the command prints "true" or "false" in stdout before exiting with 0.

The wpkg tool needs to compare versions to know whether a newly installed package is newer, older, or the same as the one already installed (assuming you are doing an upgrade.) For this reason it has a set of functions in the libdebpackages library that are used to compare whether a version is larger, smaller, or equal to another version.

The functions are available to you through the use of the --compare-versions and the --canonicalize-version commands. The compare command allows you to test whether a version is larger, smaller, or equal to another version. It is not as simple as comparing two strings because numbers are checked as decimal numbers so 10 is larger than just 1 (whereas "10" < "1" when compared as strings.) Also, versions get canonicalized first, this means 1.0.0 is equal to 1.0 and both are equal to just 1.

IMPORTANT NOTE

Debian considered the period as a full character that cannot just be optimized and thus 1.0.0 is not equal to 1.0 nor just 1 or even 1.0. or 1., all of those are distinct in Debian. It does seem logical, though, to do such an optimization. Our process considered a period (.) at the end of a version as representing nothing, so we optimize it and 1 or 1. are the exact same thing. Similarly, we optimize a zero (0) because that's the default value of a release version. So in effect any .0 gets optimized out. Where we are Debian compatible is with numbers with additional leading zeros so 1.0 and 1.00 are equal in our environment and in the Debian environment. See also Debian Version.

Contrary to the other commands, the compare versions command accepts exactly 3 parameters: two versions separated by an operator. The following are accepted by the current version1:

Syntax Operator Comments
v1 eq v2
v1 = v2
Equal Compare two versions for equality, if equal wpkg returns 0, otherwise it returns 1.
v1 ne v2
v1 != v2
v1 <> v2
Not Equal Compare two versions for inequality, if not equal wpkg returns 0, otherwise it returns 1.
This operator is not available in dpkg.
v1 le v2
v1 <= v2
v1 le-nl v2
Less or equal Determine whether the first version (v1) is smaller or equal to the second version (v2), if true then wpkg returns 0, otherwise it returns 1. By default an empty string is viewed as the smallest version. The le-nl operator sees the empty string as a larger version than any other versions.
v1 lt v2
v1 << v2
v1 < v2
v1 lt-nl v2
Less than Determine whether the first version (v1) is smaller than the second version (v2), if true then wpkg returns 0, otherwise it returns 1. By default an empty string is viewed as the smallest version. The lt-nl operator sees the empty string as a larger version than any other versions.
v1 ge v2
v1 >= v2
v1 ge-nl v2
Greater or equal Determine whether the first version (v1) is greater or equal to the second version (v2), if true then wpkg returns 0, otherwise it returns 1. By default an empty string is viewed as the smallest version. The ge-nl operator sees the empty string as a larger version than any other versions.
v1 gt v2
v1 >> v2
v1 > v2
v1 gt-nl v2
Greater than Determine whether the first version (v1) is greater than the second version (v2), if true then wpkg returns 0, otherwise it returns 1. By default an empty string is viewed as the smallest version. The gt-nl operator sees the empty string as a larger version than any other versions.

With the --verbose option, wpkg also prints the result out as either "true" or "false".

Note that if v1 or v2 represent an invalid version, then wpkg exits with 255 instead. You can also use the --canonicalize-version command to first check that a version is valid. Note however that the --canonicalize-version does not consider the empty string as valid.

  • 1. Note that the operators do not make use of a dash like in the debversion tool.