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

Prevent error if !OPTIND is unbound #18

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

billyzkid
Copy link

This PR adds a check that prevents an error when nounset is enabled (set -u) and !OPTIND is unbound, i.e. when there are no more arguments left to process and getopts_long encounters a final option that is missing a required argument. This matches the behavior of the builtin getopts command.

This PR clears OPTARG (as opposed to `unset OPTARG`) for a valid long option without a required argument (e.g. `--charlie`). I believe this matches the behavior of builtin `getopts` for valid short options without an argument.
Clear vs. unset OPTARG for valid long option without argument
Redeclare OPTARG instead of clear
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

Successfully merging this pull request may close these issues.

1 participant