jeudi 6 avril 2017

Determine If Numeric Value Is out of Range via If Statement

I am trying to construct a dynamic IF statement in bash to determine if a number is within a pre-defined range or outside of it.

some.file

-11.6

Bash Code:

check=`cat some.file`

if [ ${check} -le "-7.0" ] && [ ${check} -ge "7.0" ];
then
echo "CAUTION: Value outside acceptable range"
else
echo "Value within acceptable range"
fi

Right now, I am getting returns of "Value within acceptable range" when clearly, -11.6 is less than -7.0 and therefore out of the range.

Aucun commentaire:

Enregistrer un commentaire