Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [BUG] getopts OPTIND



dana wrote on Tue, Apr 13, 2021 at 18:28:50 -0500:
> (Resurrecting this per workers/48509)
> 
> bin_getopts() has changed a little since i posted my patch before, this looks
> a bit weirder. The test is also weird. But i confirmed that this makes it
> behave like dash, bash, and mksh (my ksh93 doesn't support local, and i still
> don't know what yash is doing):
> 
> % pbpaste | zsh-dev -f
> <1><1><3><5><7><6>
> % pbpaste | zsh-dev -f --posix-builtins
> <2><2><3><6><7><7>
> % pbpaste | dash
> <2><2><3><6><7><7>
> % pbpaste | bash
> <2><2><3><6><7><7>
> % pbpaste | mksh
> <2><2><3><6><7><7>
> % pbpaste | yash
> <3><3><3><7><7><7>
> 
> tbh i don't think i fully understand why this needs to work this way, or
> whether there are other cases that should be tested. Open to review obv

Should the descriptions of OPTIND and/or POSIX_BUILTINS in the manual be
extended as well?  (Once the behaviour is decided on, if there are still
open questions about that.)

Some more cases to test:
.
       t 0
       t 1 foo
       t 1 -- foo
       t 1 -b
.
where -b doesn't take an argument.

> @@ -96,3 +96,29 @@
> +  # Try all these the native way, then the POSIX_BUILTINS way
> +  for 1 in no_posix_builtins posix_builtins; do (
> +    setopt $1
> +    print -rn - "$1: "
> +    t 1 -a
> +    t 1 -w

> +    t 2 -a -w
> +    t 4 -a -w -e -r -a
> +    t 5 -a -w -e -a -w -e
> +    t 5 -a -w -e -r -ax -a
> +    print
> +  ); done
> +0:OPTIND calculation with and without POSIX_BUILTINS (workers/42248)
> +>no_posix_builtins: <1><1><3><5><7><6>
> +>posix_builtins: <2><2><3><6><7><7>
> 
> 




Messages sorted by: Reverse Date, Date, Thread, Author