This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # compare version $1 and $2; returns 0 if version $1 >= $2 | |
| # only the initial numeric part of a version component is considered | |
| vcompare() { | |
| local v1=$1 v2=$2 v1a v2a n1 n2 max i | |
| IFS=. read -ra v1a <<< "$v1"; IFS=. read -ra v2a <<< "$v2" | |
| ((n1=${#v1a[@]}, n2=${#v2a[@]}, max=(n1 > n2 ? n1 : n2))) | |
| # remove trailing non-digits and leading zeros (to avoid octal) | |
| for ((i=0; i < n1; ++i)) do v1a[i]=${v1a[i]%%[!0123456789]*} v1a[i]=${v1a[i]#"${v1a[i]%%[!0]*}"}; done |