This example behaves more like a standard unix command line utility. Options are processed in any order and can have modifiers. It does not work for every situation (like modifiers with spaces in them), but I've found it to be very useful for scripts that I want to have some default behavior, but occasionally I want to modify one or more parameters.
#!/bin/bash
#defaults
VAR1="Yours"
VAR2="Mine"
VAR3="Ours"
SHARENICE="false"
while [ $# -gt 0 ]; do
case "$1" in
#single parameter
-s) SHARENICE="true"
shift
;;
#modified parameters
-1) VAR1="$2"
shift 2
;;
-2) VAR2="$2"
shift 2
;;
-3) VAR3="$2"
shift 2
;;
#you could put a 'usage' function here,
#or if your last parameter has no modifier,
#like a mandatory input, it will now be at
#$1
*)
break
;;
esac
done
echo -n "$VAR1, $VAR2 and $VAR3. "
if [ "$SHARENICE" != "true" ]; then
echo "Too bad we don't get along."
else
echo "Good thing we play nice!"
fi