bug-bash
[Top][All Lists]
Advanced

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

Re: "${assoc[@]@k}" doesn't get expanded to separate words within compou


From: Lawrence Velázquez
Subject: Re: "${assoc[@]@k}" doesn't get expanded to separate words within compound assignment syntax
Date: Wed, 20 Mar 2024 00:28:19 -0400
User-agent: Cyrus-JMAP/3.11.0-alpha0-332-gdeb4194079-fm-20240319.002-gdeb41940

On Tue, Mar 19, 2024, at 11:18 PM, Zachary Santer wrote:
> As such, I would expect that
> $ declare -A assoc_2=( "${assoc_1[@]@k}" )
> would create assoc_2 as a duplicate of assoc_1. However, we see that
> the entire expansion becomes the key for a single array element, with
> its value being the empty string.

This isn't specific to ${var[@]@k}.

        $ kv1='a 1 b 2 c 3'
        $ kv2=(a 1 b 2 c 3)
        $ declare -A aa1=($kv1) aa2=(${kv2[@]}) aa3=("${kv2[@]}")
        $ declare -p aa1 aa2 aa3
        declare -A aa1=(["a 1 b 2 c 3"]="" )
        declare -A aa2=(["a 1 b 2 c 3"]="" )
        declare -A aa3=(["a 1 b 2 c 3"]="" )

A couple of previous discussions:
  - https://lists.gnu.org/archive/html/bug-bash/2020-12/msg00066.html
  - https://lists.gnu.org/archive/html/bug-bash/2023-06/msg00128.html

-- 
vq



reply via email to

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