Need some help with a script. I am trying to make sure the user enters a valid school term, like F18 F19 etc.
The letters that can be used are F S M N (which are Fall, Spring, Summer, Special) the numbers are years, 18 19 20 21 etc.
The problem with my current setup if someone missed type for example ff18, its correct, or f181 its correct, I want it to only accept, 1 letter, and 2 numbers.
Thanks in advanced.
#!/bin/bash
term_arg=$1
letter_range="[f|F|s|S|m|M|n|N]"
number_range="[10-99]"
if [[ "${term_arg}" = "" ]] || ! [[ "${term_arg}" =~ ${letter_range}${number_range} ]]; then
echo "Please specify a valid term: e.g. F18, S19, M19, etc. "
exit 1
else
echo "The term id ${term_arg} is correct"
exit 0
fi
Aucun commentaire:
Enregistrer un commentaire