Re: [PATCH] options: Always reset OPTIND in getoptsreset

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux