echo -n "How many days back would you like to check? "; read days
How can I ensure that the user has a.) entered a number between 1-30 (not 0 or 31+) and b.) has not just hit enter (ie set it to "") and if it's entered wrong, how do I start the if statement over?
I think I figured out my first question while typing. I have:
EDIT: I didnt figure it out at all
if [ "$days" != [1-30] ]; then #this doesnt work
echo "Please specify a number between 1 and 30."
echo -n "How many days back would you like to check? "; read days
else
...
fi
If they enter it wrong again, it errors. Is there a better way to do this?
echo -n "How many days back would you like to check? "; read days
while [ "$days" -lt 1 -o "$days" -gt 30 ]
do
echo "Please specify a number between 1 and 30."
echo -n "How many days back would you like to check? "; read days
done
Earnstaf,
You already have a solution for your problem with the loop offered
by Franklin.
The loop assures you that only numbers between 1 and 30 are entered.