On 10.02.2016 12:44,
Joerg.S...@fokus.fraunhofer.de wrote:
> In article <n9d32f$dk5$
1...@news.m-online.net>,
> Janis Papanagnou <
janis_pa...@hotmail.com> wrote:
>> On 09.02.2016 15:23,
Joerg.S...@fokus.fraunhofer.de wrote:
>>> In article <n9afgh$k6n$
1...@news.m-online.net>,
>>> Janis Papanagnou <
janis_pa...@hotmail.com> wrote:
>>>
>>>>> 1) You need to reset OPTIND to 1 before you start another attempt of
>>>>> option parsing
>>>>
>>>> This is not correct. You don't need to rest it in a ksh function; it will
>>>> be resetted on every function invocation.
>>>
>>> You are mistaken: OPTIND is a normal variable and it cannot be reset
>>> automatically without being in conflict with POSIX.
>>
>> You are mistaken. Ksh funktions (which, AFAIR, are not specified by POSIX)
>> behave exactly that way. You may just try it out. And it's even documented.
>
> It seems you are correct for this non-POSIX case.
As I said. And the ksh behaviour makes sense. Different from POSIX functions
ksh functions have a scope, with a couple of desirable effects; typeset in
functions declare local variables, trap signal handlers can be defined per
function, option parsing can be done in functions as for the whole program
(without affecting each other! - everything else makes no sense here), etc.
>
> The behavior however is not documented. Neither in the ksh88 nor in the ksh93
> man page.
Read, for example, Bolsky/Korn: "The [new] Kornshell". To quote from there:
"OPTIND is initialized to 1 whenever ksh, a script, or a function
is invoked."
Sadly on
http://kornshell.com/doc/ the respective links seem to be defunc
for some time now,[*] and a call of man ksh, or ksh --man will not provide
those details.
Janis
[*] Does someone know a shadow or where it moved to?