On Fri, Mar 22, 2024 at 11:23 AM Chet Ramey <chet.ra...@case.edu> wrote: > > This is what you can do with @K. > > https://lists.gnu.org/archive/html/bug-bash/2021-08/msg00119.html > > Word splitting doesn't happen on the rhs of an assignment statement, so you > use eval. The @K quoting is eval-safe.
Yeah, but what can you do with @k? $ unset assoc array assoc_copy $ declare -A assoc=( [zero]=0 [one]=1 [two]=2 ) $ declare -a array=( "${assoc[@]@k}" ) $ eval "declare -A assoc_copy=( ${assoc[*]@K} )" $ declare -p assoc array assoc_copy declare -A assoc=([two]="2" [one]="1" [zero]="0" ) declare -a array=([0]="two" [1]="2" [2]="one" [3]="1" [4]="zero" [5]="0") declare -A assoc_copy=([two]="2" [one]="1" [zero]="0" ) The difference in expansion behavior between indexed and associative array compound assignment statements doesn't make sense. As nice as it is to have expansions that expand to eval-safe expressions, needing eval less would be nicer.