On 9/9/16 9:40 AM, Vincent Lefevre wrote:
> On 2016-09-09 09:02:11 -0400, Chet Ramey wrote:
>> On 9/9/16 7:44 AM, Vincent Lefevre wrote:
>>> On 2016-09-05 19:12:54 +0000, Mark Galeck wrote:
>>>> The standard says in the section 2.2.3 on Double-Quotes and $ :
>>>> "even number of unescaped double-quotes or single-quotes, if any,
>>>> shall occur".
>>>
>>> Concerning this point, these even number of double-quotes and even
>>> number of single-quotes are fulfilled with the example below:
>>>
>>>   echo "${foo-'a"b'"}"
>>>
>>> But is this valid?
>>
>> It's unspecified, so anything goes, as per
>>
>> http://austingroupbugs.net/view.php?id=221
>>
>> "For parameter expansions other than the four varieties that provide
>> for substring processing, within the string of characters from an
>> enclosed "${" to the matching '}', the double-quotes within which
>> the expansion occurs shall preserve the literal value of all
>> characters, with the exception of the characters double-quote,
>> backquote, <dollar-sign>, and <backslash>. If any unescaped
>> double-quote characters occur within the string, other than in
>> embedded command substitutions, the behavior is unspecified."
> 
> But this will be only in Issue 8.
> 
> http://austingroupbugs.net/view.php?id=221 is about "poor
> wording", but I don't see where it the above unspecified
> in Issue 7.

OK.  Geoff's position is that the issue 7 text is a requirement on the
application, not the shell, in addition to the wording being ambiguous
about the intent that the requirement applies separately to single
and double quotes (i.e., you can't nest them).

As such, there wasn't any shell behavior to point to as correct when
interpretation 221 was being discussed, and part of the discussion
involved deciding what was correct and expressing it clearly.

The discussion, which took place in 2010, also included the point that
single quotes are not special when the expansion is within double quotes,
so there's no implication that the single quotes begin some separate
"single quote stream," and that shells didn't have to take single quotes
into account when finding the ending brace.

Since the single quotes aren't special, it would seem that the ksh93
behavior, at least, isn't correct and that the correct output is 'ab'.
But that depends on what shells do with the embedded double quotes.

So since the whole reason for the interpretation is that the wording was
bad and shells behaved differently, there can't be any conclusions
drawn from it.  It's a defect in the standard.  However...

The text in issue 8 was supposed to capture the original intent of issue 7,
even if the text in issue 7 didn't do a good job of expressing it.  If you
believe this, the construct is unspecified.

> 
> And one also has:
> 
>     "For the four varieties of parameter expansion that provide for
>     substring processing (see [xref to 2.6.2 Parameter Expansion]),
>     within the string of characters from an enclosed "${" to the
>     matching '}', the double-quotes within which the expansion occurs
>     shall have no effect on the handling of any special characters."
> 
> There's no unspecified behavior concerning the double quotes.
> So, what about the following?
> 
>   echo "${foo#'a"b'"}"

In this case, it seems to me that the single quotes are special, and the
embedded double quotes are special, so the double quote preceding the
close brace quotes it, and the expansion is incomplete (no closing brace).

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://cnswww.cns.cwru.edu/~chet/

Reply via email to