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-18 11:48 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...
====================================================================== 

---------------------------------------------------------------------- 
 (0004214) geoffclare (manager) - 2019-01-18 11:48
 http://austingroupbugs.net/view.php?id=953#c4214 
---------------------------------------------------------------------- 
Alternative resolution, based on kre's suggestion on the mailing list.

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 categorized as type <b>TOKEN</b> (see [xref to 2.10.1]), including
(recursively) any token resulting from an alias substitution, the
<b>TOKEN</b> shall be subject to alias substitution if: <ul> <li>the
<b>TOKEN</b> does not contain any quoting characters,</li> <li>the
<b>TOKEN</b> is a valid alias name (see XBD Section 3.10),</li> <li>an
alias with that name is in effect, and</li> <li>the <b>TOKEN</b> did not
result from an alias substitution of the same alias name at any earlier
recursion level,</li> </ul> except that if the <b>TOKEN</b> meets the above
conditions and would be recognized as a reserved word (see [xref to 2.4
Reserved Words]) if it occurred in an appropriate place in the input, it is
unspecified whether the <b>TOKEN</b> is subject to alias substitution.

When a <b>TOKEN</b> is subject to alias substitution, the value of the
alias shall be processed as if it had been read from the input instead of
the <b>TOKEN</b>, with token recognition (see [xref to 2.3 Token
Recognition]) resuming at the first character of the alias value. When the
end of the alias value is reached, the shell may behave as if an additional
<space> character had been read from the input after the <b>TOKEN</b> that
was replaced.  If it does not add this <space>, and the last character of
the alias value could be part of an operator token, it is unspecified
whether the current token is delimited before token recognition is applied
to the character (if any) that followed the <b>TOKEN</b> in the input.

Note: a future version of this standard may disallow adding this <space>.

If the value of the alias replacing the <b>TOKEN</b> 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, if it is a <b>TOKEN</b>, for alias substitution;
this process shall continue until a <b>TOKEN</b> is found that is not a
valid alias or an alias value does not end in such a <blank>.

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.</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>.  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 2460 line 78908 (XCU alias APPLICATION USAGE),
change:<blockquote>None.</blockquote>to:<blockquote>Care should be taken to
avoid alias values that end with a character that could be treated as part
of an operator token, as it is unspecified whether the character that
follows the alias name in the input can be used as part of the same token
(see [xref to 2.3.1]). For example, with:<pre>$ alias foo='echo 0'
$ foo>&2</pre>the shell can either pass the argument '0' to <i>echo</i> and
redirect fd 1 to fd 2, or pass no arguments to <i>echo</i> and redirect fd
0 to fd 2. Changing it to:<pre>$ alias foo='echo "0"'</pre>avoids this
problem. The alternative of adding a <space> after the '0' would also avoid
the problem, but in addition it would alter the way the alias works, as
described in [xref to 2.3.1].)

Likewise, given:<pre>$ alias foo='some_command &'
$ foo&</pre>the shell may combine the two '&' characters into an && (and)
operator.  Since the alias cannot pass arguments to <i>some_command</i> and
thus can be expected to be invoked without arguments, adding a <space>
after the '&' would be an acceptable way to prevent this.  Alternatively,
the alias could be specified as a grouping command:<pre>$ alias foo='{
some_command & }'</pre></blockquote>
On page 3721 after line 127547 (XRAT C.2.3.1), insert:<blockquote>Some
implementations add a <space> after the alias value when performing alias
substitution in order to prevent the last character of the alias value and
the first character after the alias name in the input from combining to
form an operator.  However, the extra <space> can have side-effects in
other situations, such as if the alias value ends with an unquoted
<backslash>.  Implementations which do this are encouraged to change to an
alternative method of delimiting a partial operator token at the end of an
alias value.

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                          
2019-01-09 12:32 geoffclare     Note Edited: 0004201                         
2019-01-09 12:40 geoffclare     Note Edited: 0004201                         
2019-01-15 10:44 geoffclare     Note Edited: 0004201                         
2019-01-18 11:48 geoffclare     Note Added: 0004214                          
======================================================================


Reply via email to