[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: getopts state is not localized in shell functions
From: |
Doug Kearns |
Subject: |
Re: getopts state is not localized in shell functions |
Date: |
Sat, 8 Sep 2001 00:42:05 +1000 |
User-agent: |
Mutt/1.2.5i |
On Fri, Sep 07, 2001 at 03:57:39PM +0200, Wilhelm Mueller wrote:
<snip>
> Description:
> It is not possible to use getopts to parse the arguments of shell functions.
> Using getopts with extra arguments after the variable name does not work
> either.
OPTIND is set to 1 _only_ upon invocation of the shell.
So you need to reset it to 1 before the function is called again.
> Though this behaviour is permitted by POSIX, it makes getopts almost useless
> for functions.
This is a little harsh :)
Just reset it in the function after you have finished calling getopts,
ready for the next time you call it.
<snip>
Regards,
Doug