limiting data inputs for the user

if my user has to enter the name of months to carry out a search how can I limit the input values to only the month names and nothing else?

so far my input criteria for the user is this:

i would like it so the user can only enter the months in the way i have stated. otherwise they would get an error message.

case MONTH in Jan|Feb|Mar|... you get the idea ...|Dec);; 
  *) echo Invalid month name, play again? >&2 ;; esac

i get it all bar that piece of code... what does it do?

>&2 re-directs the output to file descriptor 2, which is called "Standard error", a channel used for outputting errors usually.

It's common unix practice.

Of course I forgot the dollar sign on $MONTH ... blush. Sorry about that.

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

Thanks Very Much !!! :slight_smile:

now that i have done it for months

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.)

ok i have entered this to limit it from dates 1-31

case $DATE in [1-9]|[12][0-9]|3[01]) break;;
   *) echo Invalid date, try again >&2;;
esac

but it doesnt work. it will come up to enter the date but no matter what date i enter it just asks me to enter again.

1-9, 10-29, and 30-31 should work, are you saying they don't?