Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The best way to check that we have require version software in bash script

Tags:

bash

Which the best way to check that we have minimum require version software in bash script. E.g. git 2.16.2

like image 284
KOl Avatar asked Feb 26 '18 22:02

KOl


1 Answers

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
like image 142
John1024 Avatar answered Nov 15 '22 04:11

John1024