44 lines
1.0 KiB
Bash
44 lines
1.0 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -o pipefail # trace ERR through pipes
|
|
set -o errtrace # trace ERR through 'time command' and other functions
|
|
set -o nounset ## set -u : exit the script if you try to use an uninitialised variable
|
|
set -o errexit ## set -e : exit the script if any statement returns a non-true return value
|
|
|
|
function versionCompare () {
|
|
if [[ $1 == $2 ]]
|
|
then
|
|
echo -n '='
|
|
return
|
|
fi
|
|
local IFS=.
|
|
local i ver1=($1) ver2=($2)
|
|
# fill empty fields in ver1 with zeros
|
|
for ((i=${#ver1[@]}; i<${#ver2[@]}; i++))
|
|
do
|
|
ver1[i]=0
|
|
done
|
|
for ((i=0; i<${#ver1[@]}; i++))
|
|
do
|
|
if [[ -z ${ver2[i]} ]]
|
|
then
|
|
# fill empty fields in ver2 with zeros
|
|
ver2[i]=0
|
|
fi
|
|
if ((10#${ver1[i]} > 10#${ver2[i]}))
|
|
then
|
|
echo -n '>'
|
|
return
|
|
fi
|
|
if ((10#${ver1[i]} < 10#${ver2[i]}))
|
|
then
|
|
echo -n '<'
|
|
return
|
|
fi
|
|
done
|
|
|
|
echo -n '='
|
|
}
|
|
|
|
versionCompare "$1" "$2"
|