Le 07/12/2025 à 11:34, anonymous écrivait :

== 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

It is not buggy. You are declaring the array content which is a key with an empty value since you are providing 4 arguments to declare:

- -A
- a=(
- $'[A]=a\n[B]=b\n[C]=c'
- )

If you need to dynamically declare an associative array, you need to use:

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

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

--
Léa Gris

Reply via email to