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

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