0

I'm trying to do a simple code to know if a user input number is less or higher than a given limit. Everything seems to work fine but in some inputs it gets like this :

porter@porter-VirtualBox:~/Documents/cursito$ ./linked.sh
Calculate if a number is higher than the limit
Hi please introduce the limit: 40010
Now introduce any number: 6000
your number is higher than the limit
the difference is -34010

My code is this as follows

#!/usr/bin/env bash

echo "Calculate if a number is higher than the limit"
read -p "Hi please introduce the limit: " lim

if [ -z "$lim" ]; then
echo " you did not introduce any limit"
exit 1
fi

read -p "Now introduce any number: " num

if [ -z "$num" ]; then
echo " you did not introduce any number"
exit 1
fi


if [[ "$num" < "$lim" ]]; then
echo "your number is less than the limit" 
let "var1 = $lim - $num"
echo "the difference is $var1"
fi

if [[ "$num" > "$lim" ]]; then
echo "your number is higher than the limit"
let "var2 = $num - $lim"
echo "the difference is $var2"
fi

0 Answers0