New word splitting semantics for kvpair compound assignment

Chet Ramey <[email protected]>
Newsgroups gmane.comp.shells.bash.bugs
Organization ITS, Case Western Reserve University
Message-ID <[email protected]>
The latest push to the bash devel branch contains an implementation of some
new semantics for key-value pair compound assignments to associative
arrays, along the lines proposed in

https://lists.gnu.org/archive/html/bug-bash/2025-12/msg00125.html
and
https://lists.gnu.org/archive/html/bug-bash/2026-01/msg00013.html

In short, key-value pair assignment now expands all words of the compound
assignment, including word splitting, before identifying keys and values.

This means that something like

copy=( "${assoc[@]@k}" )

will copy an associative array, keys and values.

There are a couple of incompatibilities: since we split all words, unquoted
words in the compound assignment can potentially result in multiple keys
and values; and since we don't identify keys and values before expanding,
pathname expansion is applied to all words, including words intended to be
keys. Appropriate quoting can resolve both of these.

There is a new shopt option: kvpair_split, to control this behavior. It's
enabled (on) by default for now, since

"Currently, the behavior makes no sense at all (from a script writer's
point of view)."

from https://lists.gnu.org/archive/html/bug-bash/2026-01/msg00008.html .

Please test it out and let me know what you think, and what should change.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
		 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    [email protected]    http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc (application/pgp-signature, 203 B)
-----BEGIN PGP SIGNATURE-----

wmMEABEIACMWIQR8ATX7CIqvbGbGULm7WGnwZOp0qwUCaoMcEwUDAAAAAAAKCRC7WGnwZOp0q6dz
AJ9cB3NWf5xlbfId8rjD92W0hbuERACfWr/wk9KxDa022BThqPzhxHChsqg=
=Blwg
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.