Re: getopts doesn't properly update OPTIND when called from function

2015-06-04 Thread Martijn Dekker
Harald van Dijk schreef op 29-05-15 om 00:39: A quick patch to make sure it is global, and isn't reset when it shouldn't or doesn't need to be, is attached. You can experiment with it, if you like. I've been using dash with this patch since you posted it, and it works like a charm (including

Re: getopts doesn't properly update OPTIND when called from function

2015-06-01 Thread Herbert Xu
On Fri, May 29, 2015 at 07:50:09AM +0200, Harald van Dijk wrote: But the test script in this thread does invoke getopts with parameters that are the same in all invocations, and without modifying OPTIND. I don't see anything else in the normative sections that would make the result undefined

Re: getopts doesn't properly update OPTIND when called from function

2015-06-01 Thread Harald van Dijk
On 01/06/2015 08:29, Herbert Xu wrote: On Fri, May 29, 2015 at 07:50:09AM +0200, Harald van Dijk wrote: But the test script in this thread does invoke getopts with parameters that are the same in all invocations, and without modifying OPTIND. I don't see anything else in the normative sections

Re: getopts doesn't properly update OPTIND when called from function

2015-06-01 Thread Jilles Tjoelker
On Mon, Jun 01, 2015 at 07:30:46PM +0200, Harald van Dijk wrote: On 01/06/2015 08:29, Herbert Xu wrote: On Fri, May 29, 2015 at 07:50:09AM +0200, Harald van Dijk wrote: But the test script in this thread does invoke getopts with parameters that are the same in all invocations, and without

Re: getopts doesn't properly update OPTIND when called from function

2015-05-28 Thread Harald van Dijk
On 28/05/2015 20:54, Martijn Dekker wrote: I'm writing a shell function that extends the functionality of the 'getopts' builtin. For that to work, it is necessary to call the 'getopts' builtin from the shell function. The POSIX standard specifies that OPTIND and OPTARG are global variables,

Re: getopts doesn't properly update OPTIND when called from function

2015-05-28 Thread Harald van Dijk
On 29/05/2015 04:58, Herbert Xu wrote: Harald van Dijk har...@gigawatt.nl wrote: That isn't the problem, not exactly anyway. The problem is that getopts is required to keep internal state separately from the OPTIND variable (a single integer is insufficient to track the progress when multiple