Use GNU sort's version-sort along with the "check if input is sorted" option:
printf '%s\n%s\n' "$version" "$New_version" | sort -rVc 2>/dev/null && echo ok
The 2>/dev/null
is to drop sort's complaint when the input is not sorted; you just want to know if it's sorted or not, which is reflected in the return code.
Sample run:
$ version=1.8.0_65 $ New_version=1.8.0_111 $ printf '%s\n%s\n' "$version" "$New_version" | sort -rVc 2>/dev/null && echo ok $ version=1.8.0_650 $ printf '%s\n%s\n' "$version" "$New_version" | sort -rVc 2>/dev/null && echo ok ok $
Alternatively, do it the hard way:
oldstr=${old//./ } oldstr=${oldstr//_/ } newstr=${new//./ } newstr=${newstr//_/ } read -a oldarr <<< "$oldstr" read -a newarr <<< "$newstr" [ ${oldarr[0]} -ge ${newarr[0]} ] && [ ${oldarr[1]} -ge ${newarr[1]} ] && [ ${oldarr[2]} -ge ${newarr[2]} ] && [ ${oldarr[3]} -gt ${newarr[3]} ] && echo OK
This sets up new variables where we replace all of the dots and underscores with spaces, then feed those as here-strings into read
to split them into arrays, then we compare each element of the parallel arrays.