Ah yeah, of course, it compares numbers. 2.40.1 is not a number.
Problem is,
- lexicographic comparison as strings won't work either for comparing versions.
- just removing the dots before comparing won't work either.
I found this, which handles version components up to 3 digits each (but accomodates fewer) and gives a single string that can be lexicographically compared directly in bash (with bash comparisons such as '-ge'):
echo "2.40.1" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
2040001000
echo "2.40.10" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
2040010000
echo "2.40" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'
2040000000
You can make this a bash function so that it's easy to reuse:
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
You can then compare two version strings like so:
if [ $(version $ver1) -ge $(version $ver2) ]; then
fi