Bug 286921 - OPTIND not reset and not local to the function
OPTIND not reset and not local to the function
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: bash (Show other bugs)
i386 Linux
medium Severity low
: ---
: ---
Assigned To: Pete Graner
Ben Levenson
: Reopened
Depends On:
  Show dependency treegraph
Reported: 2007-09-11 16:55 EDT by Aleksandar Kostadinov
Modified: 2007-11-30 17:07 EST (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2007-10-19 14:35:25 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Aleksandar Kostadinov 2007-09-11 16:55:23 EDT
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv: Gecko/20070723 Iceweasel/ (Debian-

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):

How reproducible:

Steps to Reproduce:
function1 -p x -f y #parameters parsed correctly
function2 -g j -d l #no parameters detected

Actual Results:
function1 - parameters parsed correctly
function2 - no parameters detected

This is because OPTIND is a global variable modified by function1 during 
parameter parsing.

Expected Results:
both functions have parameters parsed correctly

Additional info:

At the beginning of the function put "local OPTIND=1".
Comment 1 Pete Graner 2007-09-17 16:08:28 EDT
What are you expecting it *is* documented behavior?
Comment 2 Aleksandar Kostadinov 2007-09-17 16:14:20 EDT
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?
Comment 3 RHEL Product and Program Management 2007-10-19 14:35:25 EDT
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.

Note You need to log in before you can comment on or make changes to this bug.