0

I am learning bash scripting and trying to create a number generator script but somehow the if statement causes a bug

#Take the lower and the upper value from the user
echo "Enter the minimum value:"
read minimum
echo "Enter the maximum value:"
read maximum

#Check the taken values are valid
if [[ $maximum < $minimum ]]; then
    echo "Maximum value can't be lower than minimum value"
    exit 1
fi

The minimum and maximum values always initialize themselves to % 10, so when the minimum value is 2 and the max 10 it causes an error. Similarly, when giving the min value of 400 and the max 80, it's working when it shouldn't

Turhan Ergene
  • 487
  • 1
  • 4
  • 13
  • 1
    I’m not sure what is causing the issue, but if you use `-lt` instead it works: `if [[ $maximum -lt $minimum ]]; then` – Ryan1729 May 15 '22 at 13:00
  • 1
    Also see [Why is "\[\[ 10 < 2 \]\]" true when comparing numbers in bash?](https://stackoverflow.com/q/42745497/4154375). – pjh May 15 '22 at 13:25

0 Answers0