Bash: --help feature
Is it posseble to have a --help
argument with getopts?
I'm currently using this to code the help feature:
#!/bin/bash
PROGNAME=${0##*/}
PROGVERSION=1.0
usage()
{
cat << EO
Prog description goes here.
Usage: $PROGNAME
Options:
EO
cat <<EO | column -s\& -t
-h|--help & show this output
-v|--version & show version information
EO
}
SHORTOPTS="hv"
LONGOPTS="help,version"
ARGS=$(getopt -s bash --options $SHORTOPTS \
--longoptions $LONGOPTS --name $PROGNAME -- "$@" )
eval set -- "$ARGS"
while true; do
case $1 in
-h|--help)
usage
exit 0
开发者_Python百科 ;;
-v|--version)
echo "$PROGVERSION"
exit 0
;;
--)
shift
break
;;
*)
shift
break
;;
esac
shift
done
The bash getopts builtin does not support long option names with the double-dash prefix. It only supports single-character options.
精彩评论