bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ${b+s ''}


From: Chet Ramey
Subject: Re: ${b+s ''}
Date: Wed, 20 Feb 2019 10:08:44 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:60.0) Gecko/20100101 Thunderbird/60.5.1

On 2/19/19 9:15 PM, Robert Elz wrote:
>     Date:        Sun, 17 Feb 2019 20:07:06 -0500
>     From:        Chet Ramey <address@hidden>
>     Message-ID:  <address@hidden>
> 
>   | The idea behind the bash behavior is that a
>   | null string added to a non-empty word is simply discarded,
> 
> This is clearly not POSIX compliant behaviour - POSIX requires that words
> be accumulated as entered (seemingly redundant null strings or not)
> and that quotes only get removed after field splitting has happened.

Maybe. The standard doesn't actually say that anywhere as such. But since
I wasn't talking about lexical analysis, but word expansion, every example
you give below demonstrates the behavior I described.

> Of course, no-one cares how it is actually implemented, but the
> effect has to be the same.
> 
> What's more, it is obvious that this doesn't happen consistently:
> 
>       jinx$ x=abc
>       jinx$ xy=def
>       jinx$ echo $x''y 
>       abcy
>       jinx$ 
> 
> (That's bash 5, but any other vers would do the same I think ... it is
> also correct).
> 
> There the null string is being added to a non-empty word, but is
> (correctly) not simply being discarded (or when it comes to time
> to expand the var, xy would be expanded instead of x).

Obviously we don't discard these null strings during lexical analysis. We
have to remember them through word expansion so that if a word containing
an empty quoted string expands to nothing, a null word results. That's why
$x''$y expands to a null word. It's less clear that we have to remember
them as part of a non-null word through word splitting.

But compatibility is important, so I'll take a look at what bash is doing
here.

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]