On 2012-4-18, at 19:04, ольга крыжановская <[email protected]> wrote:

> Clark, AFAIK you must declare the variable opt, OPTIND and OPTARG as
> function local variable.

Sure the opt var should be local. What I posted is just pseudo code. :)

But as I tested we should not declare OPTIND and OPTARG as local or getopts in 
both global scope and functions would not work. Seems like ksh implicitly 
treats them as local bars in funcs. Not sure if it's by design. Needs 
confirmation from David.
> 
> David, can you add the comment that OPTIND and OPTARG must be function
> local variables in such cases to getopts --man, please?
> 
> Olga
> 
> On Wed, Apr 18, 2012 at 11:42 AM, Clark J. Wang <[email protected]> wrote:
>> Is it safe to write scripts like following since OPTIND and OPTARG are
>> global(?) vars?
>> 
>> function func1
>> {
>>     while getopts "ab:" opt; do
>>         ...
>>     done
>> }
>> 
>> function func2
>> {
>>     while getopts "ab:" opt; do
>>         ...
>>     done
>> }
>> 
>> while getopts "ab:" opt; do
>>     case $opt in
>>         a)  func1 ... ;;
>>         b)  func2 ... ;;
>>     esac
>> done
>> 
>> _______________________________________________
>> ast-users mailing list
>> [email protected]
>> https://mailman.research.att.com/mailman/listinfo/ast-users
>> 
> 
> 
> 
> -- 
>       ,   _                                    _   ,
>      { \/`o;====-    Olga Kryzhanovska   -====;o`\/ }
> .----'-/`-/     [email protected]   \-`\-'----.
>  `'-..-| /       http://twitter.com/fleyta     \ |-..-'`
>       /\/\     Solaris/BSD//C/C++ programmer   /\/\
>       `--`                                      `--`

_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users

Reply via email to