#! /bin/sh

# This is how you get ahold of the name of the script
SCRIPTNAME=`basename $0`

# This is how you write a function
usage () {
  echo "Usage: $SCRIPTNAME [-a|-b arg|-c arg]"
  exit 1
}

# Here is how you extract flags and their arguments
while getopts ab:c: arg
do
  case $arg
  in
    a) echo "Flag was a"
       break
       ;;
    b) echo "Flag was b"
       ARG=$OPTARG
       echo "- Argument was $ARG"
       break
       ;;
    c) echo "Flag was c"
       ARG=$OPTARG
       echo "- Argument was $ARG"
       break
       ;;
    *) usage  # This is that function we wrote above
       ;;
  esac
done

# Shift off the arguments that were used
shift `expr $OPTIND - 1`

# Here you use whatever you understood from the invoking arguments

