No word splitting for assignment-like expressions in compound assignment
From:
Alexey Izbyshev
Subject:
No word splitting for assignment-like expressions in compound assignment
Date:
Fri, 24 Jul 2020 03:11:16 +0300
User-agent:
Roundcube Webmail/1.4.4
Hello!
I have a question about the following behavior:
$ Z='a b'
$ A=(X=$Z)
$ declare -p A
declare -a A=([0]="X=a b")
$ A=(X$Z)
$ declare -p A
declare -a A=([0]="Xa" [1]="b")
I find it surprising that no word splitting is performed in the first
compound assignment. I realize that skipping word splitting may be
desirable if a subscript is given (e.g. "A=([0]=$Z)") to make it
consistent with normal variable assignment[1], but in this case it looks
like a bug.
I've reproduced the described behavior on bash 4.4.20 (Ubuntu 18.04),
3.1.17 (CentOS 5) and self-built 5.1-alpha release.
Some other discoveries:
* Brace expansion is performed for "A=(X=a{x,y}b)" by all bash versions
mentioned above (which is inconsistent with normal variable assignment).
* Globbing for "A=(X=a?b)" is performed by bash 3.1.17, but not by other
versions.