As the thread title implies, getopt is the way to go. Here's a simple example:
OPTS=`getopt -n $0 -o p:h: --long port:,host: -- $@`
eval set -- "$OPTS"
case "$1" in
-p|--port) echo "port = $2"; shift 2 ;;
-h|--host) echo "host = $2"; shift 2 ;;
--) shift ; break ;;
Here, both -p (or --port) and -h (or --host) require one to input values; the ':' that is placed after the options p and h above, imply this. If an arg is not required, then don't use the ':' after the option.