Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #16623

Re: No word splitting for assignment-like expressions in compound assignment

From Oğuz <oguzismailuysal@gmail.com>
Newsgroups gnu.bash.bug
Subject Re: No word splitting for assignment-like expressions in compound assignment
Date 2020-07-27 11:05 +0300
Message-ID <mailman.132.1595837136.2739.bug-bash@gnu.org> (permalink)
References <87o8o1zfpn.fsf@hobgoblin.ariadne.com> <F420E583-E5D4-48BB-98E3-044C700BA07A@larryv.me> <e64878396a22641351ff3b910fdc99d8@ispras.ru> <CAH7i3LpA=oZt8E8ecAH8eCO+92oYxHXhymB6HaNDbyVeB+R3Fg@mail.gmail.com>

Show all headers | View raw


27 Temmuz 2020 Pazartesi tarihinde Alexey Izbyshev <izbyshev@ispras.ru>
yazdı:

> On 2020-07-27 10:06, Lawrence Velázquez wrote:
>
>> On Jul 27, 2020, at 1:31 AM, Dale R. Worley <worley@alum.mit.edu> wrote:
>>> Interesting.  The documentation for 4.2.53(1) says this about parameter
>>> assignments generally, with no special rules for compound assignments:
>>>
>>>       All
>>>       values undergo tilde expansion, parameter and variable expansion,
>>> com-
>>>       mand  substitution, arithmetic expansion, and quote removal (see
>>> EXPAN-
>>>       SION below).  ...  Word  splitting  is  not
>>>       performed,  with the exception of "$@" as explained below under
>>> Special
>>>       Parameters.  Pathname expansion is not  performed.
>>>
>>> So it seems like the word splitting in "A=(X$Z)" is incorrect.  So is
>>> pathname expansion in that context.
>>>
>>
>>
>> If word splitting were not performed in compound assignments, this...
>>
>>     foo=(a b c)
>>
>> ...would not work. If pathname expansion were not performed in compound
>> assignments, this...
>>
>>     foo=(*)
>>
>> ...would not work. Arrays would become significantly less usable if
>> word splitting and pathname expansion were not allowed in compound
>> assignments.
>>
>> To be clear, I don't consider word splitting and expansions in compound
> assignments to be a problem: this is well-known and long-standing behavior,
> even though it doesn't seem to be explicitly documented. In particular, I
> expect word splitting to happen in "A=(X$Z)" case. But I expect it to
> happen in "A=(X=$Z)" too, and the lack of it seems unintentional to me.


I agree, anything that forms a valid assignment statement in isolation is
exempt from word splitting and that indeed seems like a bug or very poor
implementation choice.

    $ Z='a b'
    $ A=(X=$Z X[123]=$Z X[qwerty]=$Z X+=$Z)
    $ declare -p A
    declare -a A=([0]="X=a b" [1]="X[123]=a b" [2]="X[qwerty]=a b"
[3]="X+=a b")


>
> Alexey
>
>

-- 
Oğuz

Back to gnu.bash.bug | Previous | Next | Find similar


Thread

Re: No word splitting for assignment-like expressions in compound assignment Oğuz <oguzismailuysal@gmail.com> - 2020-07-27 11:05 +0300

csiph-web