echo " "
echo "Enter the month in which you wish to search
(Please enter months in the form of Jan, Feb, Mar, etc...): "
read MONTH
case $MONTH in [Jj]an|[Ff]eb|[Mm]ar|[Aa]pr|[Mm]ay|[Jj]un|[Jj]ul|[Aa]ug|[Ss]ep|[Oo]ct|[Nn]ov|[Dd]ec);;
*) echo "Invalid month name" ;;
esac
grep $5 "$MONTH" tempfile > tempmonth
people are inputting data in this loop. i am trying to validate this loop so only months are entered. if the user enters the wrong data how do i loop it back so the user has to enter the month again. this is not the start of my code so using "start over" will not work.
while true; do
echo Enter month
read MONTH
case $MONTH in ...ok...) break;;
*) echo Invalid month name, try again >&2 ;;
esac
done
grep $5 "$MONTH" tempfile >tempmonth
how do i restrict user inputs for date based on the month chosen?
is it:
while true; do
echo " "
echo "Enter Date of the Month (1-31): "
read DATE
case $DATE in [1-31]);;
*) echo " "
echo "Invalid date, try again" >&2;;
esac
done
grep $4 "$DATE" *.hits >tempfile
The wildcard is not valid, you are looking for 1-3 or 1.
case $DATE in [1-9]|[12][0-9]|3[01]) break;;
*) echo Invalid date, try again >&2;;
esac
Adapting it to be stricter for February etc left as an exercise ... Maybe you could put the upper limit of the range in a variable when you read the month.
(I'd hate to use a script which prompts interactively, myself.)