Message ID | ZkngRVxkiUil_9aG@gondor.apana.org.au (mailing list archive) |
---|---|
State | Superseded |
Delegated to: | Herbert Xu |
Headers | show |
Series | options: Always reset OPTIND in getoptsreset | expand |
On 19/05/2024 12:19, Herbert Xu wrote: > On Wed, Jan 04, 2023 at 04:50:34PM +0000, Harald van Dijk wrote: >> >> Personally, I do think it is better if shells allow assigning arbitrary >> values to OPTIND, including unsetting it, and only have the getopts command >> raise an error if the value is non-numeric, but that is my personal opinion >> and I don't see much of a problem if dash decides to go the other way, >> unless POSIX makes it explicit that it is not permitted for shells to do >> this. FWIW, I did make that change for my version, <https://github.com/hvdijk/gwsh/commit/0df0ba33748eb3881b07cb724fd4fa54422ef2bc>, >> if that change is desired for dash it is easy to apply. > > I've decided to make getoptsreset always do the reset, regardless > of the value of OPTIND. Why else would you assign it anyway? This interacts terribly with the not fully reliable but nevertheless fairly commonly used "local OPTIND". When the local OPTIND goes out of scope and the prior value of OPTIND is restored, the expectation is not that option processing restarts from the beginning. Cheers, Harald van Dijk
diff --git a/src/options.c b/src/options.c index 4d0a53a..c74e4fe 100644 --- a/src/options.c +++ b/src/options.c @@ -393,7 +393,7 @@ setcmd(int argc, char **argv) void getoptsreset(const char *value) { - shellparam.optind = number(value) ?: 1; + shellparam.optind = 1; shellparam.optoff = -1; }