Which the best way to check that we have minimum require version software in bash script. E.g. git 2.16.2
git
provides its version info like this:
$ git --version
git version 2.11.0
GNU sort
understands version numbers and can sort them:
$ (echo a version 2.16.3; git --version) | sort -Vk3
git version 2.11.0
min version 2.16.3
$ (echo a version 2.9.3; git --version) | sort -Vk3
min version 2.9.3
git version 2.11.0
We can combine this to make a test:
if (echo a version 2.16.3; git --version) | sort -Vk3 | tail -1 | grep -q git
then
echo "Good enough."
else
echo "Not good"
fi
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With