[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: @K transformation
From: |
Léa Gris |
Subject: |
Re: @K transformation |
Date: |
Thu, 19 Aug 2021 12:37:02 +0200 |
User-agent: |
Telnet/1.0 [tlh] (PDP11/DEC) |
Le 19/08/2021 à 12:09, Koichi Murase écrivait :
$ printf '<%s>\n' "${A[@]@A}"
<declare>
<-A>
<A=([adsf]="456 789" ["foo bar"]="123 456" )>
The problem of ${A[@]@A} is that it is not so useful when one wants to
define a clone associative array with a different name but with the
same contents as A. Instead, using ${A[@]@K}, one could do
$ declare -A "B=(${A[@]@K})"
to clone the associative array. It is even possible to save the
contents of an associative array in an indexed array as
$ declare -a "saved=(${A[@]@K})"
Hmm..., but for this case, one could actually simply store the
contents in a scalar:
$ saved="${A[*]@K}"
Current implementation of @K is pretty-much useless for the dialog use-case:
#!/usr/bin/env bash
declare -A assoc=(
[P]=piano
[TB]='foldable table'
['CH AIR']=chair
)
options=("${assoc[@]@K}")
#typeset -p options
#exit
choice="$(
dialog \
--backtitle "Test" \
--title "Test" \
--menu "Test" \
0 0 4 \
"${options[@]}" \
2>&1 >/dev/tty
)"
Inline with "${array[@]}" expanding as multiple arguments!
"${assoc[@]@K}" shall have expanded into arguments and not expand quotes
as string content.
This would have made the @K expansion usable for dialog.
Currently the associative array's key values pairs need be added to the
options array in a for loop as:
options=()
for k in "${!assoc[@]}"; do
options+=("$k" "${assoc[$k]}")
done
--
Léa Gris
- feature request array expansion of keys values pairs and for k v loop, Léa Gris, 2021/08/18
- Re: feature request array expansion of keys values pairs and for k v loop, Koichi Murase, 2021/08/18
- @K transformation, Ilkka Virta, 2021/08/19
- Re: @K transformation, Koichi Murase, 2021/08/19
- Re: @K transformation,
Léa Gris <=
- Re: @K transformation, Koichi Murase, 2021/08/19
- Re: @K transformation, Chet Ramey, 2021/08/20
- Re: @K transformation, Léa Gris, 2021/08/20
- Re: @K transformation, Lawrence Velázquez, 2021/08/20
- Re: @K transformation, Greg Wooledge, 2021/08/20
- Re: @K transformation, Léa Gris, 2021/08/20
- use-cases promote thinking of limited application, L A Walsh, 2021/08/22
- Re: use-cases promote thinking of limited application, Koichi Murase, 2021/08/22
- Re: use-cases promote thinking of limited application, L A Walsh, 2021/08/23
- Re: use-cases promote thinking of limited application, Koichi Murase, 2021/08/23