I want to share a piece of code which gives me problems when comparing variables
The variables are probably strings and i can not make arithmetic comparisons
As you see i have tried different ways to do it but without success
It seems Bash have problems with decimals ?
So i tried to remove the period n $GSVS and $YYY but with no success
Code: Select all
GSVS2=`echo $GSVS | sed 's/.//g'
YYYY2=`echo $YYY | sed 's/.//g'
Code: Select all
#!/bin/bash
wget -q -O ext "https://extensions.gnome.org/extension-info/?pk=307&shell_version=$GSVS"
GSVS="$(DISPLAY=":0" gnome-shell --version | tr -cd "0-9." | cut -d'.' -f1,2)" #| sed 's/.//g'
XXX=`sed "s/\([0-9]*\.[0-9]*[0-9\.]*\)/\n\1/g" ext | grep "pk" | grep "version" | sed "s/^\([0-9\.]*\).*$/\1/" | sort -V`
YYY=`sed "s/\([0-9]*\.[0-9]*[0-9\.]*\)/\n\1/g" ext | grep "pk" | grep "version" | sed "s/^\([0-9\.]*\).*$/\1/" | sort -V | tail -1`
echo "Gnome-shell version : $GSVS"
echo
echo "Available versions : $XXX"
echo
echo "Last available version : $YYY"
# Tests but not working
#GSVS=`expr $GSVS + 0`
#YYY=`expr $YYY + 0`
#GSVS=$GSVS/.*}
#YYY=$YYY/.*}
if (( $YYY -eq $GSVS )) ; then echo "=" ; fi
if [[ $YYY -gt $GSVS ]] ; then echo ">" ; fi
if test $YYY -le $GSVS ; then echo "<" ; fi
#./comp-versions.sh: line 19: ((: 3.24 -eq 3.14 : syntax error: invalid arithmetic operator (error token is ".24 -eq 3.14 ")
#./comp-versions.sh: line 20: [[: 3.24: syntax error: invalid arithmetic operator (error token is ".24")
#./comp-versions.sh: line 21: test: 3.24: integer expression expected
Which documentations are good about this ?