Red Hat Bugzilla – Bug 286921
OPTIND not reset and not local to the function
Last modified: 2007-11-30 17:07:10 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:220.127.116.11) Gecko/20070723 Iceweasel/18.104.22.168 (Debian-22.214.171.124-0etch1)
Description of problem:
It is a documented behaviour but not what the user(me) expects.
I have 2 complex functions that do parameter parsing with the getopts
built-in command. OPTIND is used to keep the number of next parameter to
parse. It is reset to 1 whenever a new shell is invoked.
I makes more sense to be reset to 1 *for the function* when called so that
function's parameter parsing is independent.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
function1 -p x -f y #parameters parsed correctly
function2 -g j -d l #no parameters detected
function1 - parameters parsed correctly
function2 - no parameters detected
This is because OPTIND is a global variable modified by function1 during
both functions have parameters parsed correctly
At the beginning of the function put "local OPTIND=1".
What are you expecting it *is* documented behavior?
That is a feature request. I can't see any sense in current behavior.
Or will you point me to the bash bug tracking system if any?
This bug is filed against RHEL 3, which is in maintenance phase.
During the maintenance phase, only security errata and select mission
critical bug fixes will be released for enterprise products. Since
this bug does not meet that criteria, it is now being closed.
For more information of the RHEL errata support policy, please visit:
If you feel this bug is indeed mission critical, please contact your
support representative. You may be asked to provide detailed
information on how this bug is affecting you.