Bug 286921 - OPTIND not reset and not local to the function
Summary: OPTIND not reset and not local to the function
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 3
Classification: Red Hat
Component: bash
Version: 3.0
Hardware: i386
OS: Linux
medium
low
Target Milestone: ---
Assignee: Pete Graner
QA Contact: Ben Levenson
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2007-09-11 20:55 UTC by Aleksandar Kostadinov
Modified: 2007-11-30 22:07 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2007-10-19 18:35:25 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Aleksandar Kostadinov 2007-09-11 20:55:23 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.6) Gecko/20070723 Iceweasel/2.0.0.6 (Debian-2.0.0.6-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):


How reproducible:
Always


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

At the beginning of the function put "local OPTIND=1".

Comment 1 Pete Graner 2007-09-17 20:08:28 UTC
What are you expecting it *is* documented behavior?

Comment 2 Aleksandar Kostadinov 2007-09-17 20:14:20 UTC
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 Program Management 2007-10-19 18:35:25 UTC
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:
http://www.redhat.com/security/updates/errata/
 
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.