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

[BUG] getopts OPTIND



testfunc() {
    echo $*;
    echo "OPTIND is $OPTIND, `(shift "$(($OPTIND - 1))"; echo next $1)`";
    echo 'I do getopts :a: varname'; getopts ':a:' varname;
    echo "OPTIND is $OPTIND, `(shift "$(($OPTIND - 1))"; echo next $1)`";
    echo 'I do getopts :a: varname'; getopts ':a:' varname;
    echo "OPTIND is $OPTIND, `(shift "$(($OPTIND - 1))"; echo next $1)`";
    echo 'I do getopts :a: varname'; getopts ':a:' varname;
    echo "OPTIND is $OPTIND, `(shift "$(($OPTIND - 1))"; echo next $1)`";
}

(testfunc -a -w -e -r -a)

Execution in bash:

-a -w -e -r -a
OPTIND is 1, next -a
I do getopts :a: varname
OPTIND is 3, next -e
I do getopts :a: varname
OPTIND is 4, next -r
I do getopts :a: varname
OPTIND is 5, next -a

execution in zsh:

-a -w -e -r -a
OPTIND is 1, next -a
I do getopts :a: varname
OPTIND is 3, next -e
I do getopts :a: varname
OPTIND is 3, next -e
I do getopts :a: varname
OPTIND is 4, next -r

Best regards


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