bug-bash
[Top][All Lists]
Advanced

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

Re: @K transformation


From: Léa Gris
Subject: Re: @K transformation
Date: Sat, 21 Aug 2021 00:11:50 +0200
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

Le 21/08/2021 à 00:06, Chet Ramey écrivait :
On 8/19/21 6:37 AM, Léa Gris wrote:

#!/usr/bin/env bash

declare -A assoc=(
  [P]=piano
  [TB]='foldable table'
  ['CH AIR']=chair
)

options=("${assoc[@]@K}")

The best way to clone an associative array is:

declare -A options
eval options=\( "${assoc[@]@K}" \)

The quoting @K performs is eval-safe.


Although I was not attempting to clone the Associative array but turn it into a flat array with interleaved key and value each as own element.

options=(
 key
 value
 next key
 next value
 ...k
 ...v
)

--
Léa Gris




reply via email to

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