44 lines
868 B
Bash
Executable File
44 lines
868 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# `vercomp()` is copied from: http://stackoverflow.com/a/4025065
|
|
|
|
# Usage: vercomp <version 1> <version 2>
|
|
# return codes:
|
|
# 0: version 1 and version 2 are the same
|
|
# 1: version 1 is higher
|
|
# 2: version 2 is higher
|
|
|
|
|
|
vercomp () {
|
|
if [[ $1 == $2 ]]
|
|
then
|
|
return 0
|
|
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
|
|
return 1
|
|
fi
|
|
if ((10#${ver1[i]} < 10#${ver2[i]}))
|
|
then
|
|
return 2
|
|
fi
|
|
done
|
|
return 0
|
|
}
|
|
|
|
vercomp $1 $2
|