I am writing a small script that asks a user to insert a number from 1-10. The script will then tell the user if the number is between the requested values, and continue from there.
However, I am having an issue trying to get the script to read back to the screen if the value is less than 1 or greater than 10. Each time the script is executed, whether correct or not, the script will exit and go to the echo statement after "done".
I am trying to create an "infinite loop" if the user keeps inputting the incorrect value.
The echo statement after "done" is the second part of my script, however that isn't the part I am having issues with.
Thank you for any help provided.
Script:
echo "Please type a number between 1-10."
read insertnum
while [ "$insertnum" -ge 1 -a "$insertnum" -le 10 ]
do
if [ "$insertnum" -ge 1 -a "$insertnum" -le 10 ]
then
# Prompt the user that their answer is acceptable
echo "Your answer is between 1-10"
echo
break
else
# Prompt the user that their answer is not acceptable
echo "Your number is not between 1-10."
echo
echo "Please type a number between 1-10."
read insertnum
echo
fi
done
echo "We will now do a countdown from $insertnum to 0 using a for loop."