Interpretations

Answering questions that may arise related to the meaning of portions of an IEEE standard concerning specific applications.

IEEE Standards Interpretations for IEEE Std 1003.2™-1992 IEEE Standard for Information Technology--Portable Operating System Interfaces (POSIX®)--Part 2: Shell and Utilities

Copyright © 1996 by the Institute of Electrical and Electronics Engineers, Inc. 3 Park Avenue New York, New York 10016-5997 USA All Rights Reserved.

Interpretations are issued to explain and clarify the intent of a standard and do not constitute an alteration to the original standard. In addition, interpretations are not intended to supply consulting information. Permission is hereby granted to download and print one copy of this document. Individuals seeking permission to reproduce and/or distribute this document in its entirety or portions of this document must contact the IEEE Standards Department for the appropriate license. Use of the information contained in this document is at your own risk.

IEEE Standards Department, Copyrights and Permissions, 445 Hoes Lane, Piscataway, New Jersey 08855-1331, USA

Interpretation Request #139
Topic: getopts Relevant Sections: 4.27.2

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- arguments..." 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".

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 sponsor.

Rationale for Interpretation
None.