开发者

Bash: --help feature

开发者 https://www.devze.com 2023-04-08 02:23 出处:网络
Is it posseble to have a --help argument with getopts? I\'m currently using this to code the 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消