Bash compare version numbers

Here is a little script to help compare version numbers in the format X.X.X using bash/shell. This can be good if you are trying to find out which version is higher for something like an upgrade.

versionlte() {
    [  "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
versionlt() {
    [ "$1" = "$2" ] && return 1 || versionlte $1 $2
}

You can then use this as an iffe.

lowerVersion="1.0.2"
higherVersion="2.3.1"

versionlt $lowerVersion $higherVersion && upgradeRequired=true || upgradeRequired=false