URL:
  <https://savannah.gnu.org/bugs/?67782>

                 Summary: bash split $() for array initialization but not for
associative array initialization
                   Group: The GNU Bourne-Again SHell
               Submitter: None
               Submitted: Sun 07 Dec 2025 10:34:21 AM UTC
                Category: None
                Severity: 3 - Normal
                Priority: 5 - Normal
              Item Group: None
                  Status: None
                 Privacy: Public
             Assigned to: None
             Open/Closed: Open
         Discussion Lock: Unlocked


    _______________________________________________________

Follow-up Comments:


-------------------------------------------------------
Date: Sun 07 Dec 2025 10:34:21 AM UTC By: Anonymous
Reading the manual, I think this is a bug, not quite sure. Sorry if it isn't
one.

* Bash version : 5.2.21(1)-release
* OS release : ubuntu 24.04.3 LTS (Noble Numbat)
* Architectures :
        * x86_64-pc-linux-gnu
        * aarch64-unknown-linux-gnu (raspberry pi)

== What is working as expected ==

unset a  ; declare  a=(
  $(
    echo a
    echo b
    echo c
  )
)
echo Nb of elements : ${#a[@]}
declare -p a


This produces a 3 elements array.

== What seems buggy to me ==

Strangely, when using associative array, $() are not split

unset a  ; declare -A a=(
  $(
    echo [A]=a
    echo '[B]=b'
    echo ['C']=c
  )
)
echo Nb of elements : ${#a[@]}
declare -p a


The output shows there is only one element in the associative array:


Nb of elements : 1
declare -A a=([$'[A]=a\n[B]=b\n[C]=c']="" )


== What I expect ==

I expect the $() to be split also in associative array. In my example, the
expected output is :


Nb of elements : 3
declare -A a=([C]="c" [B]="b" [A]="a" )









    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?67782>

_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/

Attachment: signature.asc
Description: PGP signature

Reply via email to