I need a script to check if yad (and other programs) version number is >= to a specific number. For example I have:
$ yad --version
0.40.0 (GTK+ 3.24.8)
$ gedit --version
gedit - Version 3.32.0
$ bash --version
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
- For yad new features are added between Ubuntu 16.04 and 19.04
- For gedit the ability to pass Window geometry is lost in newer versions
- bash complicates tests as the version number is in the middle of the first line.
An environment variable will not exist for all programs like bash has:
$ echo $BASH_VERSION
5.0.3(1)-release
You might want to try GNU
sort
's-V
(--version-sort
), along with-C
(--check=quiet
):then to return
0
(true) if the version is at least the given one and1
(false) otherwise:I developed a script that draws on answers in Stack Overflow. One of those answers led to a Dell Employee writing version number comparisons in 2004 for the DKMS application.
Sample Tests
Real life application
The code
The bash script below needs to be marked as executable using the command
chmod a+x script-name
. I'm using the name/usr/local/bin/testver
:You can use
dpkg --compare-versions
. Usage example:This returns "true" because version 4.0 is less than ("lt") version 5.0.
On the other hand the following does not return anything:
This is because version 4.0 is not greater ("gt") than 5.0.
Comparison operators for
dpkg --compare-versions
are:lt le eq ne ge gt
(treat empty version as earlier than any version);lt-nl le-nl ge-nl gt-nl
(treat empty version as later than any version);< << <= = >= >> >
(only for compatibility with control file syntax).