Another simple example in bash (if you do not care about the switches' names) :
#!/bin/bash
parseArguments() {
if [[ $# -lt 3 ]]; then
echo "Usage: $0 host user pass"
exit 1
fi
host="$1"
user="$2"
pass="$3"
# do you stuff here, and put the following at the main part of the script :
parseArguments() $@
f=0
while [ $# -gt 0 ]; do
case "$1" in
-o?*)
# handles things like -oValue
o=`expr "$1" : '..\(.*\)'`
;;
-o)
# handles things like -o Value
o="$2"
shift
;;
-f)
# Just a flag (on/off)
f=1
;;
*)
break
;;
esac
shift
done
echo "o=$o, f=$f"
# Loop through remaining arguments (arguments without a hyphen)
for arg in "$@"; do
echo "$arg"
done