I have a scenario where I am taking difference of two numbers.
Then the calculated difference needs to be checked within a range.
If it lie within that range then display status as success, else display failure.
Below is my code
Range = -1 to 1
var1=12.23
var2=13.23
diff=$(echo "($var1-$var2)"| bc -l)
echo $diff
if [ "$diff" -ge -1 ] && [ "$diff" -le 1 ]; then
echo "$diff" "success"
else
echo "Not within range -1 to 1"
echo "Failure"
fi
Error getting like below
script.sh: 8: [: Illegal number: -1.00
bcor some other tool to calculate the value of($var1 - $var2) > 1(etc.) instead and use the boolean value of that in your script.