set -- -q -w -e r -t -y echo "*** no OPTIND, optstring:'we' args:$*" var=QWERTY while getopts "we" var; do echo "var:'$var' OPTIND:$OPTIND" done # unfortunately, "rc:0" is shown since while's overall exitcode is "success" echo "exited: var:'$var' OPTIND:$OPTIND"