Skip to content

Prevent error if !OPTIND is unbound #18

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

Merged
merged 12 commits into from
Dec 17, 2024
7 changes: 3 additions & 4 deletions lib/getopts_long.bash
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,9 @@ getopts_long() {

# Missing argument
if [[ -z "${OPTARG}" ]]; then
OPTARG="${!OPTIND}" && OPTIND=$(( OPTIND + 1 ))
[[ -z "${OPTARG}" ]] || return 0

if [[ "${optspec_short:0:1}" == ':' ]]; then
if [[ -n "${!OPTIND:-}" ]]; then
OPTARG="${!OPTIND}" && OPTIND=$(( OPTIND + 1 ))
elif [[ "${optspec_short:0:1}" == ':' ]]; then
OPTARG="${!optvar}" && printf -v "${optvar}" ':'
else
[[ "${OPTERR}" == 0 ]] || \
Expand Down
Loading