WG15 Defect Report Ref: 9945-2-139
Topic: getopts

This is an approved interpretation of 9945-2:1993.


Last update: 1997-05-20



	Topic:			getopts
	Relevant Sections:	4.27.2

Defect Report:
	From: andrew@novell.co.uk (Andrew Josey)
	Date: Thu, 17 Aug 1995 15:38:41 +0100

Attached is a request for interpretation of ISO/IEC 9945-2:1993.

The standard specifies (section 4.27.2, p291, lines 4658-4662)
"when the end of options is encountered, the getopts utility
shall exit with a return value greater than zero; the shell
variable OPTIND shall be set to the index of the first nonoption-
argument, where the first -- argument is considered to be an
option-argument if there are no other nonoption-arguments 
appearing before it, or the value $#+1 if there are no nonoption-

This has raised two problems when conformance testing;

(i) The standard does not specify whether an argument that resembles
an option but is not listed as an option to getopts should be classified 
as an option or not.

(ii) The text quoted above appears to conflict with lines 4631-4633:  
"each time it is invoked, the getopts utility shall
place the value of the next option in the shell variable specified by
the name operand and the index of the next argument to be processed in
the shell variable OPTIND".

Based on the above what should be the value for OPTIND for the
arguments "-a -b -c x y z" if only "-a" and "-b" are specified as
valid options to getopts?

Some conformance tests tests assume OPTIND should point to "x", 
but it seems equally reasonable to expect it to point to "-c".

thanks you for your attention in this matter.

Interpretation response
The standard does not speak to this issue, and as such no
conformance distinction can be made between alternative 
implementations based on this. This is being referred to the


Forwarded to Interpretations group: Aug 29 1995
Recirculated for 30 day review: Oct 23 1995
Finalised: Nov 29 1995