How to know if decimal number is major to another?


EDIT/UPDATE: Solutioned! Check how I did this scrolling down.

I’m trying to create an auto-update script, but the problem is that the only mode I can do it is removing the dots from the version number, what can (and probablly will) give an error on the future.

The problem is that I can’t use numbers with dot/decimal numbers with "(( $num > $num2 ))". This is a very specific problem :/

The actual script is this:

VER=$(curl --silent "" | grep -Po '"tag_name": "\K.*?(?=")' | tr -d .)
INSTALLVER=$(cat $HOME/my-path/example-program-version.txt | tr -d .)
if (( $VER > $INSTALLVER )); then
echo need_update
yes "i" | sudo myinstallscript example
echo already_updated

(I get the $INSTALLVER number with "myinstallscript")

If you can help me, very thanks! Also, very thanks for reading!


@KamilCuk Thanks! Problem solved. I picked a reply from the link that you sent, and I adapted this putting the "head" command and putting this inside the variable.


LATESTVER=`echo -e "$VER\n$INSTALLVER" | sort -V -r | head -n 1`

(Echo the two variables with echo, one in each line, then sort them putting the major on the first line with sort, getting just the first line with head, and putting this on the "LATESTVER" variable)

Answered By – Felipecconde

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published