Michael Greenberg <[email protected]> wrote: > Hi all, > > I'm unsure of what `getopts` should do to `OPTIND` when working with > grouped options. > > Consider the following script: > > ```sh > getopts "ab:c:" opt -ab hi -c hello ; printf "OPTIND=%1s opt=%1s OPTARG=%-5s > ?=%d\n" "$OPTIND" "$opt" "$OPTARG" "$?" > getopts "ab:c:" opt -ab hi -c hello ; printf "OPTIND=%1s opt=%1s OPTARG=%-5s > ?=%d\n" "$OPTIND" "$opt" "$OPTARG" "$?" > getopts "ab:c:" opt -ab hi -c hello ; printf "OPTIND=%1s opt=%1s OPTARG=%-5s > ?=%d\n" "$OPTIND" "$opt" "$OPTARG" "$?" > getopts "ab:c:" opt -ab hi -c hello ; printf "OPTIND=%1s opt=%1s OPTARG=%-5s > ?=%d\n" "$OPTIND" "$opt" "$OPTARG" "$?" > ``` > > Existing shells seem to exhibit one of two behaviors: early and late > incrementing. In the early-incrementing group, dash and mksh (and > smoosh) all set OPTIND to 2, then 3, then 5. In the late-incrementing > group, bash, zsh, and ksh set OPTIND to 1, then 3, then 5. yash seems to > be non-conformant, setting OPTIND first to 1:2, then 3, then 5.
It seems that the shells you call "early-incrementing" are mistaken since the standard requires OPTIND to point to the next argument tp process in the next getopts call. Jörg -- EMail:[email protected] (home) Jörg Schilling D-13353 Berlin [email protected] (work) Blog: http://schily.blogspot.com/ URL: http://cdrecord.org/private/ http://sf.net/projects/schilytools/files/'
