A NOTE has been added to this issue. ====================================================================== http://austingroupbugs.net/view.php?id=953 ====================================================================== Reported By: wpollock Assigned To: ajosey ====================================================================== Project: 1003.1(2013)/Issue7+TC1 Issue ID: 953 Category: Shell and Utilities Type: Clarification Requested Severity: Objection Priority: normal Status: Interpretation Required Name: Wayne Pollock Organization: User Reference: Section: 2.3.1 Alias Substitution Page Number: 2322 Line Number: 73690-73705 Interp Status: Pending Final Accepted Text: See http://austingroupbugs.net/view.php?id=953#c3113
====================================================================== Date Submitted: 2015-06-04 00:22 UTC Last Modified: 2019-01-09 12:29 UTC ====================================================================== Summary: Alias expansion is under-specified ====================================================================== Relationships ID Summary ---------------------------------------------------------------------- related to 0000736 grammatically accept zero or more Shell... related to 0001048 deprecate alias and unalias related to 0001055 unspecified how much is parsed before e... ====================================================================== ---------------------------------------------------------------------- (0004201) geoffclare (manager) - 2019-01-09 12:29 http://austingroupbugs.net/view.php?id=953#c4201 ---------------------------------------------------------------------- This is a proposed new resolution which addresses comments made since http://austingroupbugs.net/view.php?id=953#c3113 both here and on the mailing list. There have been a <b>lot</b> of comments, so if I missed anything please reply <b>on the mailing list</b> and (if I agree) I will edit this note. All page and line numbers are for the 2016 and 2018 editions. On page 2348 line 74794-74805 (XCU 2.3.1 Alias Substitution), change:<blockquote>After a token has been delimited, but before applying the grammatical rules in Section 2.10, a resulting word that is identified to be the command name word of a simple command shall be examined to determine whether it is an unquoted, valid alias name. However, reserved words in correct grammatical context shall not be candidates for alias substitution. A valid alias name (see XBD Section 3.10) shall be one that has been defined by the <i>alias</i> utility and not subsequently undefined using <i>unalias</i>. Implementations also may provide predefined valid aliases that are in effect when the shell is invoked. To prevent infinite loops in recursive aliasing, if the shell is not currently processing an alias of the same name, the word shall be replaced by the value of the alias; otherwise, it shall not be replaced. If the value of the alias replacing the word ends in a <blank>, the shell shall check the next command word for alias substitution; this process shall continue until a word is found that is not a valid alias or an alias value does not end in a <blank>.</blockquote>to:<blockquote>After a TOKEN has been delimited, including (recursively) any token resulting from an alias substitution, the TOKEN shall be subject to alias substitution if: <ul> <li>the TOKEN does not contain any quoting characters,</li> <li>the TOKEN is a valid alias name (see XBD Section 3.10),</li> <li>an alias with that name is in effect,</li> <li>the TOKEN did not result from an alias substitition of the same alias name at any earlier recursion level,</li> <li>the TOKEN is not recognized as a reserved word (see [xref to 2.4 Reserved Words] and the examples in [xref to XRAT C.2.3.1]), and</li> <li>the TOKEN will be parsed as the command name word of a simple command when the grammatical rules in Section 2.10 are applied.</li> </ul> An implementation may defer the effect of a change to an alias but the change shall take effect no later than the completion of the currently executing <i>complete_command</i> (see [xref to XCU 2.10 Shell Grammar]). Changes to aliases shall not take effect out of order. Implementations may provide predefined aliases that are in effect when the shell is invoked. If the value of the alias is not a simple command (see [xref to 2.9.1]), or contains any of: <ul> <li>a comment</li> <li>a variable assignment</li> <li>a redirection</li> <li>unbalanced single-quotes or double-quotes</li> (except within a command substitution), the behavior is unspecified. When a TOKEN is subject to alias substitution, the value of the alias shall be processed to form tokens (see [xref to 2.3]) and the resulting tokens shall replace the TOKEN. If the value of the alias replacing the TOKEN ends in a <blank> that would be unquoted after substitution, and optionally if it ends in a <blank> that would be quoted after substitution, the shell shall check the next TOKEN in the input for alias substitution; this process shall continue until a TOKEN is found that is not a valid alias or an alias value does not end in such a <blank>.</blockquote> On page 2351 line 74901-74904 (XCU 2.5.3 Shell Variables) change:<blockquote>This variable, when and only when an interactive shell is invoked, shall be subjected to parameter expansion (see Section 2.6.2) by the shell and the resulting value shall be used as a pathname of a file containing shell commands to execute in the current environment.</blockquote>to:<blockquote>This variable, when and only when an interactive shell is invoked, shall be subjected to parameter expansion (see Section 2.6.2) by the shell and the resulting value shall be used as a pathname of a file. Before any interactive commands are read, the shell shall tokenize (see [xref to XCU 2.3 Token Recognition]) the contents of the file, parse the tokens as a <i>program</i> (see [xref to XCU 2.10 Shell Grammar]), and execute the resulting commands in the current environment. (In other words, the contents of the ENV file are not parsed as a single <i>compound_list</i>, unlike the contents of a dot script. This distinction matters because it influences when aliases take effect.)</blockquote> On page 2358 line 75202-75204 (XCU 2.6.3 Command Substitution), change:<blockquote>With the $(<i>command</i>) form, all characters following the open parenthesis to the matching closing parenthesis constitute the <i>command</i>. Any valid shell script can be used for <i>command</i>, except a script consisting solely of redirections which produces unspecified results.</blockquote>to:<blockquote>With the $(<i>command</i>) form, all characters following the open parenthesis to the matching closing parenthesis constitute the <i>command</i>. With both the backquoted and $(<i>command</i>) forms, <i>command</i> shall be tokenized (see [xref to XCU 2.3 Token Recognition]) and parsed (see [xref to XCU 2.10 Shell Grammar]). It is unspecified whether <i>command</i> is parsed and executed as a <i>program</i> (as for a shell script) or is parsed as a single <i>compound_list</i> that is executed after the entire <i>command</i> has been parsed. With the $(<i>command</i>) form any valid <i>program</i> can be used for <i>command</i>, except a <i>program</i> consisting solely of redirections which produces unspecified results.</blockquote> On page 2393 line 76554 (XCU 2.14 dot DESCRIPTION), change:<blockquote>The shell shall execute commands from the <i>file</i> in the current environment.</blockquote>to:<blockquote>The shell shall tokenize (see [xref to XCU 2.3 Token Recognition]) the contents of the <i>file</i>, parse the tokens (see [xref to XCU 2.10 Shell Grammar]), and execute the resulting commands in the current environment. It is unspecified whether the commands are parsed and executed as a <i>program</i> (as for a shell script) or are parsed as a single <i>compound_list</i> that is executed after the entire file has been parsed.</blockquote> On page 2394 line 76620 (XCU 2.14 eval), change:<blockquote>The <i>eval</i> utility shall construct a command by concatenating <i>arguments</i> together, separating each with a <space> character. The constructed command shall be read and executed by the shell.</blockquote>to:<blockquote>The <i>eval</i> utility shall construct a command string by concatenating <i>arguments</i> together, separating each with a <space> character. The constructed command string shall be tokenized (see [xref to XCU 2.3 Token Recognition]), parsed (see [xref to XCU 2.10 Shell Grammar]), and executed by the shell in the current environment. It is unspecified whether the commands are parsed and executed as a <i>program</i> (as for a shell script) or are parsed as a single <i>compound_list</i> that is executed after the entire constructed command string has been parsed.</blockquote> On page 2459 line 78855 (XCU alias), change:<blockquote>An alias definition provides a string value that shall replace a command name when it is encountered; see [xref to 2.3.1].</blockquote>to:<blockquote>An alias definition provides a string value that shall replace a command name when it is encountered. For information on valid string values, and the processing involved, see [xref to 2.3.1].</blockquote> On page 3721 after line 127547 (XRAT C.2.3.1), insert:<blockquote>Implementations differ in how alias substitution is performed when the alias value does not have the form of a simple command. For example, given:<pre>$ alias foo='some_command &' $ foo&</pre>some, but not all, implementations retokenize the two '&' characters into an && (and) operator. Some, but not all, shell implementations do not process changes to alias definitions until the current <tt>compound_list</tt> (see [xref to XCU 2.10 shell grammar]) has completed. In these shells, alias changes do not take effect until the end of the dot script, <b>eval</b> command, function invocation, <b>if</b> statement, <b>case</b> statement, <b>for</b> statement, <b>while</b> statement, or <b>until</b> statement containing the alias change. Many shell implementations execute the contents of a file, typically <tt>~/.profile</tt>, when invoked as a login shell. The standard developers are unaware of any such implementations that process the contents of <tt>~/.profile</tt> (and similar startup files) as a single <tt>compound_list</tt>, so alias changes in <tt>~/.profile</tt> typically do take effect before the end of <tt>~/.profile</tt>.</blockquote> Issue History Date Modified Username Field Change ====================================================================== 2015-06-04 00:22 wpollock New Issue 2015-06-04 00:22 wpollock Status New => Under Review 2015-06-04 00:22 wpollock Assigned To => ajosey 2015-06-04 00:22 wpollock Name => Wayne Pollock 2015-06-04 00:22 wpollock Section => 2.3.1 Alias Substitution 2015-06-04 09:26 joerg Note Added: 0002694 2016-02-04 17:01 Don Cragun Page Number => 2322 2016-02-04 17:01 Don Cragun Line Number => 73690-73705 2016-02-04 17:01 Don Cragun Interp Status => --- 2016-02-04 17:04 Don Cragun Project 1003.1(2008)/Issue 7 => 1003.1(2013)/Issue7+TC1 2016-03-04 09:49 joerg Note Added: 0003089 2016-03-04 09:50 joerg Note Edited: 0003089 2016-03-04 11:39 joerg Note Edited: 0003089 2016-03-04 11:40 joerg Note Edited: 0003089 2016-03-04 15:11 joerg Note Edited: 0003089 2016-03-31 16:29 rhansen Note Added: 0003113 2016-03-31 16:30 rhansen Note Edited: 0003113 2016-03-31 16:32 nick Note Edited: 0003113 2016-03-31 16:33 nick Interp Status --- => Pending 2016-03-31 16:33 nick Final Accepted Text => See bugnote: 3113 2016-03-31 16:33 nick Status Under Review => Interpretation Required 2016-03-31 16:33 nick Resolution Open => Accepted As Marked 2016-03-31 16:33 nick Final Accepted Text See bugnote: 3113 => See http://austingroupbugs.net/view.php?id=953#c3113 2016-03-31 16:33 nick Note Edited: 0003113 2016-03-31 16:34 nick Tag Attached: tc3-2008 2016-03-31 16:34 rhansen Note Edited: 0003113 2016-03-31 16:40 rhansen Note Edited: 0003113 2016-04-01 12:29 ajosey Interp Status Pending => Proposed 2016-04-01 12:29 ajosey Note Added: 0003116 2016-04-10 22:09 jilles Note Added: 0003148 2016-04-11 14:31 chet_ramey Note Added: 0003149 2016-04-11 20:59 shware_systems Note Added: 0003150 2016-04-12 08:58 joerg Note Added: 0003151 2016-04-12 12:58 chet_ramey Note Added: 0003152 2016-04-12 14:49 joerg Note Added: 0003153 2016-04-13 09:07 joerg Note Edited: 0003153 2016-04-13 17:15 chet_ramey Note Added: 0003154 2016-04-13 17:43 Don Cragun Note Edited: 0003151 2016-04-14 09:29 joerg Note Added: 0003155 2016-04-14 09:33 joerg Note Edited: 0003155 2016-04-14 09:34 joerg Note Edited: 0003155 2016-04-14 16:22 kre Note Added: 0003156 2016-04-14 16:37 kre Note Edited: 0003156 2016-04-14 19:39 chet_ramey Note Added: 0003157 2016-04-14 20:18 rhansen Relationship added related to 0000736 2016-04-14 20:33 shware_systems Note Added: 0003158 2016-04-14 22:15 eblake Note Added: 0003159 2016-04-14 23:12 rhansen Note Added: 0003160 2016-04-15 09:35 kre Note Added: 0003161 2016-04-15 10:06 kre Note Added: 0003162 2016-04-15 13:49 shware_systems Note Added: 0003163 2016-04-15 19:09 chet_ramey Note Added: 0003164 2016-04-15 19:10 chet_ramey Note Edited: 0003164 2016-04-17 23:49 rhansen Note Added: 0003165 2016-04-17 23:50 rhansen Note Edited: 0003165 2016-04-17 23:51 rhansen Note Edited: 0003165 2016-04-18 12:47 chet_ramey Note Added: 0003166 2016-04-18 21:21 rhansen Note Added: 0003167 2016-04-18 21:21 rhansen Note Edited: 0003167 2016-04-18 21:22 rhansen Resolution Accepted As Marked => Reopened 2016-04-28 15:18 rhansen Note Added: 0003178 2016-04-28 15:30 rhansen Relationship added related to 0001048 2016-05-02 21:30 stephane Note Added: 0003195 2016-05-03 09:30 joerg Note Added: 0003196 2016-05-03 11:08 stephane Note Added: 0003197 2016-05-04 06:38 stephane Note Added: 0003198 2016-06-02 16:53 rhansen Relationship added related to 0001055 2017-01-18 15:25 ajosey Interp Status Proposed => Approved 2017-01-18 15:25 ajosey Note Added: 0003553 2017-01-18 16:07 ajosey Note Deleted: 0003553 2017-01-18 16:08 ajosey Interp Status Approved => Pending 2017-01-18 16:08 ajosey Note Added: 0003555 2019-01-09 12:29 geoffclare Note Added: 0004201 ======================================================================