Quick and dirty parsing procedure for unix shell scripts
parse_command_line ()
{
typeset -i user_opt help_opt password_opt verbose_opt
typeset errmsg
arg_cou=$#
while [ "$#" -gt 0 ]
do
case "$1" in
-@([U]) ) let user_opt=user_opt+1 ;;
-P ) let password_opt=password_opt+1 ; ask_pass=0 ;;
-option1 ) ;;
-option2 ) ;;
-option3 ) ;;
-@([hH?])) help_opt=1;;
-v*(erbose)) let verbose_opt=verbose_opt+1 ;;
*)
if [ user_opt -eq 1 ];then
USER="$1"; user_opt=0
elif [ password_opt -eq 1 ];then
PASS="$1"; password_opt=0
elif [ verbose_opt -eq 1 ];then
verbose_level="$1"; verbose_opt=0
else
### help_opt=1
CMD=$* ; break
fi
;;
esac
shift
done
if [ arg_cou -eq 0 ] ; then
help_opt=1 ; errmsg="Nothing to do"
fi
for opt in user password ; do
if [ ${opt}_opt -ne 0 ] ; then
help_opt=1 ; errmsg="${errmsg}\n${opt} is absent"
fi
done
if [ verbose_opt -ne 0 ] ; then
verbose_level=$verbose_opt
fi
if [ help_opt -eq 1 ]; then
help "$errmsg"
fi
}