Validate and sort input

Hi,

This will most likely be a simple answer.

Currently I have a situation where my script will be sent various options:

-o1 -o2 -oe3@somthing.com

Now, if I want to run a certain command based on the option I am sent, I am doing the following.

for o in $(echo $options)
do
  if [ $o == "1" ]
  then
  
run commands
        exit 0
  fi
  if [ $o == "2" ]
  then
          run commands
        exit 0
  fi
done

However you will notice from my first example I gave "-oe3@something.com"

I need to be able to find where "-eXXX" is and then remove the 'e' and use the bit after (3@something.com). Or if it is easier, just forget about the "e" and look for anything with "@" init, but I would perfer to do the "e" method.

This next bit is later on at somepoint.

I will then want to "validate" what I have to check that is it a valid email address (You know so that it has an @ sign a domain name etc.

You might go with getopts to process your options:

your_script -a -b -c -e email@address -f
OPTIND=1

while getopts abce:f
do
  case $ARGS in
    a) do something for option a
    ;;
    b) do something for option b
    ;;
    c) do something for option c
    ;;
    e) this_option=$OPTARG
        do something for option e based on the option
    ;;
    f) do something for option f
    ;;
  esac
done

Thank you for your reply, unforuntaly in my particular situation I can't use getopts

I guess then just capture the positional parameters ($1, $2 etc) and process them via the necessary commands such as awk or cut.

email=`echo $3 | awk -F-oe '{print $2}'`