[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: No word splitting for assignment-like expressions in compound assign
Re: No word splitting for assignment-like expressions in compound assignment
Mon, 27 Jul 2020 11:05:31 +0300
27 Temmuz 2020 Pazartesi tarihinde Alexey Izbyshev <firstname.lastname@example.org>
> On 2020-07-27 10:06, Lawrence Velázquez wrote:
>> On Jul 27, 2020, at 1:31 AM, Dale R. Worley <email@example.com> wrote:
>>> Interesting. The documentation for 4.2.53(1) says this about parameter
>>> assignments generally, with no special rules for compound assignments:
>>> values undergo tilde expansion, parameter and variable expansion,
>>> mand substitution, arithmetic expansion, and quote removal (see
>>> SION below). ... Word splitting is not
>>> performed, with the exception of "$@" as explained below under
>>> 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...
>> ...would not work. Arrays would become significantly less usable if
>> word splitting and pathname expansion were not allowed in compound
>> 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
$ Z='a b'
$ A=(X=$Z X=$Z X[qwerty]=$Z X+=$Z)
$ declare -p A
declare -a A=(="X=a b" ="X=a b" ="X[qwerty]=a b"
Re: No word splitting for assignment-like expressions in compound assignment, Chet Ramey, 2020/07/28