You can't compare versions as any kind of number, including floats, nor as strings as each .
-separated section individually needs to be compared numerically. You need to compare them specifically as versions, e.g. using GNU sort for -V
to sort a list of version numbers into lowest to highest order:
$ cat tst.sh
#!/usr/bin/env bash
required_version=2.38.0
actual_version=10.7.45
highest_version=$(printf '%s\n%s\n' "$required_version" "$actual_version" | sort -V | tail -1)
if [[ $highest_version == $actual_version ]]; then
echo "=== PASSED ==="
else
echo "=== FAILED ==="
fi
$ ./tst.sh
=== PASSED ===
If you don't have GNU sort
you could always write your own comparison function, e.g.:
$ cat tst.sh
#!/usr/bin/env bash
required_version=2.38.0
actual_version=10.7.45
compare_vers() {
local a b n
IFS='.' read -r -a a <<< "$1"
IFS='.' read -r -a b <<< "$2"
(( "${#a[@]}" > "${#b[@]}" )) && n="${#a[@]}" || n="${#b[@]}"
for (( i=0; i<n; i++ )); do
if (( "${a[i]:0}" > "${b[i]:0}" )); then
echo 'BIGGER'
return
elif (( "${a[i]:0}" < "${b[i]:0}" )); then
echo 'SMALLER'
return
fi
done
echo 'EQUAL'
}
rslt=$(compare_vers "$actual_version" "$required_version")
if [[ $rslt == "BIGGER" ]]; then
echo "=== PASSED ==="
else
echo "=== FAILED ==="
fi
$ ./tst.sh
=== PASSED ===