View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000458 | 1003.1(2008)/Issue 7 | Shell and Utilities | public | 2011-06-03 21:33 | 2013-04-16 13:06 |
Reporter | eblake | Assigned To | ajosey | ||
Priority | normal | Severity | Objection | Type | Error |
Status | Closed | Resolution | Accepted As Marked | ||
Name | Eric Blake | ||||
Organization | Red Hat | ||||
User Reference | ebb.expansion.2 | ||||
Section | 2.6.2 Parameter Expansion | ||||
Page Number | 2306 | ||||
Line Number | 72704 | ||||
Interp Status | Approved | ||||
Final Accepted Text | 0000458:0000857 | ||||
Summary | 0000458: Interpretation of $10 | ||||
Description | The standard states that: "The parameter name or symbol can be enclosed in braces, which are optional except for positional parameters with more than one digit or when parameter is followed by a character that could be interpreted as part of the name." [line 72700] But "$?a" has always been equivalent to ${?}a, even though it fits the pattern of a non-positional parameter followed by a character that could be interpreted as part of a name. The standard then goes on to say: "If the parameter name or symbol is not enclosed in braces, the expansion shall use the longest valid name (see XBD Section 3.230, on page 70), whether or not the symbol represented by that name exists." [line 72704] The phrase "symbol represented by that name" is awkward, given the use of "parameter symbol" as the counterpart to "parameter name" moments earlier; that is, the term "symbol" should consistently represent a digit or a special parameter character. This proposal uses "variable" instead, while being careful of the fact that line 72496 defines "variable" only in the context of a "parameter name" and not a "parameter symbol". Furthermore, since "1", "-", "@", "$", etc. are not valid names by XBD 3.230, this means the longest valid name is the empty string when referring to a single-digit positional parameter or to a special parameter symbol. Meanwhile, on the dash list, a question was raised on whether $10 must be the same as ${1}0, or whether it might also be parsed as ${10}: http://www.spinics.net/lists/dash/msg00556.html Historically, $10 always meant ${1}0, and the wording about a multi-digit positional parameter requiring braces was intended to imply that if braces are absent, a single-digit positional parameter is used; but since the standard does not actually state that, a person could interpret the constraint for braces being required on multi-digit parameters to be an application constraint, such that the implementation is then free to provide the use of $10 as ${10} as an extension for applications that are not strictly compliant. Finally, shells have always historically output a literal $ if the character following $ was neither a name nor a recognized symbol: $ sh -c 'echo $+' $+ In the interest of allowing future extensions to new special parameters, or for diagnostics on suspicious unquoted $, this proposal intentionally leaves that behavior unspecified. Option 1 of this proposal mandates the traditional behavior (and means that dash has a bug); Option 2 tries to permit the dash behavior as an extension but may render existing scripts non-compliant. Personally, I prefer option 1, but I am proposing both to get group consensus. Either way, an interpretation is needed. | ||||
Desired Action | Option 1 At line 72701, change: ...or when parameter is followed by a character that could be interpreted as part of the name. to: ...or when parameter is a name and is followed by a character that could be interpreted as part of the name. At line 72704, change: If the parameter name or symbol is not enclosed in braces, the expansion shall use the longest valid name (see XBD Section 3.230, on page 70), whether or not the symbol represented by that name exists. to: If the parameter is not enclosed in braces, and is a name, the expansion shall use the longest valid name (see XBD Section 3.230, on page 70), whether or not the variable represented by that name exists. Otherwise, the parameter is a single-character symbol, and behavior is unspecified if that character is neither a digit nor one of the special parameters (see XCU 2.5.2). At line 72768, add to the non-normative Examples: ${parameter} In this example, the effects of omitting braces are demonstrated. a=1 set 2 echo ${a}b-$ab-${1}0-${10}-$10 1b--20--20 Option 2 At line 72701, change: ...or when parameter is followed by a character that could be interpreted as part of the name. to: ...or when parameter is a name and is followed by a character that could be interpreted as part of the name. At line 72704, change: If the parameter name or symbol is not enclosed in braces, the expansion shall use the longest valid name (see XBD Section 3.230, on page 70), whether or not the symbol represented by that name exists. to: If the parameter is not enclosed in braces, and is a name, the expansion shall use the longest valid name (see XBD Section 3.230, on page 70), whether or not the variable represented by that name exists. Otherwise, the parameter is a symbol, and behavior is unspecified if the symbol is a multi-digit number, or if the symbol is not a digit nor one of the special parameters (see XCU 2.5.2). | ||||
Tags | tc1-2008 |
|
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: ------------- Scripts in existing practice are known to depend on the behavior described in Option 1 of the Desired Actions. Notes to the Editor (not part of this interpretation): ------------------------------------------------------- See Desired Actions, Option 1 for recommended action to take here. |
|
Interpretation proposed 10 August 2011 for final 30 day review |
|
Interpretation approved 12 Sept 2011 |
Date Modified | Username | Field | Change |
---|---|---|---|
2011-06-03 21:33 | eblake | New Issue | |
2011-06-03 21:33 | eblake | Status | New => Under Review |
2011-06-03 21:33 | eblake | Assigned To | => ajosey |
2011-06-03 21:33 | eblake | Name | => Eric Blake |
2011-06-03 21:33 | eblake | Organization | => Red Hat |
2011-06-03 21:33 | eblake | User Reference | => ebb.expansion.2 |
2011-06-03 21:33 | eblake | Section | => 2.6.2 Parameter Expansion |
2011-06-03 21:33 | eblake | Page Number | => 2306 |
2011-06-03 21:33 | eblake | Line Number | => 72704 |
2011-06-03 21:33 | eblake | Interp Status | => --- |
2011-06-16 15:13 | msbrown | Tag Attached: tc1-2008 | |
2011-06-16 15:16 | msbrown | Interp Status | --- => Pending |
2011-06-16 15:16 | msbrown | Note Added: 0000857 | |
2011-06-16 15:16 | msbrown | Status | Under Review => Interpretation Required |
2011-06-16 15:16 | msbrown | Resolution | Open => Accepted As Marked |
2011-06-16 15:17 | msbrown | Final Accepted Text | => 0000458:0000857 |
2011-08-10 15:24 | ajosey | Interp Status | Pending => Proposed |
2011-08-10 15:24 | ajosey | Note Added: 0000931 | |
2011-09-12 15:23 | ajosey | Interp Status | Proposed => Approved |
2011-09-12 15:23 | ajosey | Note Added: 0000963 | |
2013-04-16 13:06 | ajosey | Status | Interpretation Required => Closed |