A NOTE has been added to this issue. ====================================================================== https://austingroupbugs.net/view.php?id=1784 ====================================================================== Reported By: kre Assigned To: ====================================================================== Project: Issue 8 drafts Issue ID: 1784 Category: Shell and Utilities Type: Error Severity: Objection Priority: normal Status: New Name: Robert Elz Organization: User Reference: Section: XCU 3 / getopts Page Number: 2955 - 2959 Line Number: 98803 - 98966 Final Accepted Text: ====================================================================== Date Submitted: 2023-10-22 06:14 UTC Last Modified: 2023-12-11 17:50 UTC ====================================================================== Summary: getopts specification needs fixing (multiple issues) ======================================================================
---------------------------------------------------------------------- (0006600) Don Cragun (manager) - 2023-12-11 17:50 https://austingroupbugs.net/view.php?id=1784#c6600 ---------------------------------------------------------------------- On P67, L2057-2058 (XBD 3.244 Option-Argument definition) change:<blockquote>A parameter that follows certain options. In some cases an option-argument is included within the same argument string as the option—in most cases it is the next argument.</blockquote>to:<blockquote>A parameter that follows certain options. In some cases an option-argument immediately follows the option character within the same argument string as the option; otherwise the option-argument is the next argument string.</blockquote> On page 2995 line 98801 change:<blockquote><pre><i>getopts</i> <i>optstring</i> <i>name</i> [<i>arg</i>...]</pre></blockquote>to:<blockquote><pre><i>getopts</i> <i>optstring</i> <i>name</i> [<i>param</i>...]</pre></blockquote> And globally rename s/arg/param/ elsewhere in the remainder of the getopts page. On page 2995 lines 98806-98808 Change: <blockquote>Each time it is invoked, the <i>getopts</i> utility shall place the value of the next option in the shell variable specified by the <i>name</i> operand and the index of the next argument to be processed in the shell variable <i>OPTIND</i>. Whenever the shell is invoked, <i>OPTIND</i> shall be initialized to 1.</blockquote>to<blockquote>When the shell is first invoked, the shell variable <i>OPTIND</i> shall be initialized to 1. Each time <i>getopts</i> is invoked, it shall place the value of the next option found in the parameter list in the shell variable specified by the <i>name</i> operand and the shell variable <i>OPTIND</i> shall be set as follows:<ul><li>When <i>getopts</i> successfully parses an option that takes an option-argument (that is, a character followed by <colon> in <i>optstring</i>, and exit status is 0), the value of <i>OPTIND</i> shall be the integer index of the next parameter to be searched for an option character. Index 1 identifies the first element of the parameter list.</li><li>When <i>getopts</i> reports end of options (that is, when exit status is 1), the value of <i>OPTIND</i> shall be the integer index of the next element of the parameter list (if any; see below).</li><li>In all other cases, the value of <i>OPTIND</i> is unspecified, but shall encode the information needed for the next invocation of <i>getopts</i> to resume parsing options after the option just parsed</li></ul></blockquote> Replace Lines 98830-98835 with:<blockquote>When the end of options is encountered, the <i>getopts</i> utility shall exit with a return value of one; the shell variable <i>OPTIND</i> shall be set to the index of the argument containing the first operand in the parameter list, or the value 1 plus the number of elements in the parameter list if there are no operands in the parameter list; the <i>name</i> variable shall be set to the <question-mark> character. Any of the following shall identify the end of options: the first "--" element of the parameter list that is not an option-argument, finding an element of the parameter list that is not an option-argument and does not begin with a '−', or encountering an error.</blockquote> Change lines 98836-98837 from:<blockquote>The shell variables <i>OPTIND</i> and <i>OPTARG</i> shall be local to the caller of getopts and shall not be exported by default.</blockquote>to:<blockquote>The shell variables <i>OPTIND</i> and <i>OPTARG</i> shall not be exported by default.</blockquote> Change lines 98840-98841 from:<blockquote>The shell variable specified by the <i>name</i> operand, <i>OPTIND</i>, and <i>OPTARG</i> shall affect the current shell execution environment;</blockquote>to:<blockquote>The <i>getopts</i> utility can affect <i>OPTIND</i>, <i>OPTARG</i>, and the shell variable specified by the <i>name</i> operand, within the current shell execution environment;</blockquote> On P2956, L98845-98846 change:<blockquote>... or with an <i>OPTIND</i> value modified to be a value other than 1, produces unspecified results</blockquote>to:<blockquote>... or with an <i>OPTIND</i> value modified by the application to be a value other than 1, produces unspecified results</blockquote> On P2956, L98861-98863 change:<blockquote> If the option-argument is not supplied as a separate argument from the option character, the value in <i>OPTARG</i> shall be stripped of the option character and the '−'.</blockquote>to:<blockquote> Whether or not the option-argument is supplied as a separate argument from the option character, the value in <i>OPTARG</i> shall only be the characters of the option-argument.</blockquote> Change P2956, L98868-98869 from:<blockquote>The <i>getopts</i> utility by default shall parse positional parameters passed to the invoking shell procedure. If <i<args</i> are given, they shall be parsed instead of the positional parameters.</blockquote>to:<blockquote>By default, the list of parameters parsed by the <i>getopts</i> utility shall be the positional parameters currently set in the invoking shell environment (<tt>"$@"</tt>). If <i<param</i> operands are given, they shall be parsed instead of the positional parameters. Note that the next element of the parameter list need not exist; in this case, <i>OPTIND</i> will be set to <tt>$#+1</tt> or the number of <i>param</i> operands plus 1</blockquote> Issue History Date Modified Username Field Change ====================================================================== 2023-10-22 06:14 kre New Issue 2023-10-22 06:14 kre Name => Robert Elz 2023-10-22 06:14 kre Section => XCU 3 / getopts 2023-10-22 06:14 kre Page Number => 2955 - 2959 2023-10-22 06:14 kre Line Number => 98803 - 98966 2023-10-22 06:40 kre Tag Attached: issue8 2023-10-28 05:08 Don Cragun Relationship added related to 0001535 2023-10-28 05:10 Don Cragun Relationship added related to 0001393 2023-10-28 05:10 Don Cragun Relationship added parent of 0000351 2023-10-28 05:19 kre Note Added: 0006555 2023-10-28 05:36 kre Note Added: 0006556 2023-10-28 06:25 Don Cragun Note Added: 0006558 2023-10-28 06:27 Don Cragun Relationship deleted related to 0001535 2023-10-28 06:28 Don Cragun Relationship deleted related to 0001393 2023-10-28 06:34 Don Cragun Relationship deleted parent of 0000351 2023-10-28 06:34 kre Note Edited: 0006556 2023-11-13 18:09 shware_systems Note Added: 0006568 2023-11-13 20:16 kre Note Added: 0006569 2023-11-14 09:44 geoffclare Tag Detached: issue8 2023-11-15 22:23 salewski Issue Monitored: salewski 2023-12-11 17:37 geoffclare Note Added: 0006598 2023-12-11 17:41 Don Cragun Note Added: 0006599 2023-12-11 17:50 Don Cragun Note Added: 0006600 ======================================================================