debversion
Introduction
Testing that a version string is a valid Debian version string (i.e. as accepted by wpkg) can be done with the debversion tool1.
There are two possible command lines. One to test the validity of a version and one to compare two versions against each others.
Verify a Version
Verify a version string with the first form:
debversion [-c|-p] <version>
In this case, debversion returns 0 if the version string is a valid Debian version and 1 if not.
The following command line options can be used with the first form to print out the version when valid:
- --canonicalize (or -c) to transform the input into the shortest possible form (i.e. 1.0.0 becomes 1.0; 0:3.5.9 becomes 3.5.9; etc.)
- --print (or -p) to print the version string as is.
Compare Versions
Compare two versions using the second form of the command line:
debversion <v1> -op <v2>
In this case the debversion tool compares v1 against v2 and returns one of:
- 0 when v1 -op v2 is true;
- 1 when v1 -op v2 is false;
- 2 when one of v1 or v2 or both are not valid Debian versions;
- 3 when -op is not a valid operator.
The valid operators are -lt (less than), -le (less or equal), -eq (equal), -ne (not equal), -ge (greater or equal) and -gt (greater.) These are the same as the test command line tool.
Inline Help
With --help/-h or no options and no version on the command line, the tool prints out a usage screen in stderr and exit with 1.
Examples
debversion 0:1.2.0-1 -eq 1.2 is true debversion 0:1.2.0-1 -ge 1.2 is true debversion 0:1.2.0-1 -lt 1.2 is false debversion 1:1.2.0-1 -ne 1.2 is true debversion -c 0:1.2.0-1 prints 1.2 debversion -c 3:1.2.5-2 prints 3:1.2.5-2
See Also
- 1. Note that the wpkg tool has command line options that are similar in functionality to what the debversion tool offers. See the --canonalize-version and --compare-versions command line documentation pages.