Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double hyphen not handled correctly in some situations #15

Open
dodecatheon opened this issue Apr 4, 2023 · 0 comments
Open

Double hyphen not handled correctly in some situations #15

dodecatheon opened this issue Apr 4, 2023 · 0 comments

Comments

@dodecatheon
Copy link

Try

_usage () { echo "usage" 1>&2; exit ${1:-0}; }
_die () { printf "\n$1\n" 1>&2; _usage ${2:-1}; }
while read args ; do
  OPTIND=1
  while getopts_long ":hvab: alpha bravo: charlie" OPT  $args ; do
    case "$OPT" in
      h|help   ) _usage          ;; # E.g., help option
      v|verbose) ((++verbose))   ;; # E.g., an incrementing option
      a|alpha  ) alpha=1         ;; # E.g., non-arg-requiring option
      b|bravo  ) bravo="$OPTARG" ;; # E.g., argument-requiring option
      charlie  ) charlie=1       ;; # E.g., long-option-only
      ':') _die "OPTION '${OPTARG}': MISSING ARGUMENT" 1;;
      '?') _die "UNKNOWN OPTION: '${OPTARG}'"          2;;
    esac
    echo "OPT=$OPT, OPTIND=$OPTIND, OPTARG=$OPTARG"
  done
done < <( cat <<EOF
-a-- param
EOF
)

and compare with the behavior of getopts. getopts is correctly able to stop parsing when the double-hyphen is grouped with the non-argument-requiring option, whether or not it is space separated, and whether or not '-:' is included in the shortopt spec.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant