|
From: | Léa Gris |
Subject: | Re: No expansions performed while declaring an associative array using a list of keys and values |
Date: | Fri, 11 Dec 2020 15:45:27 +0100 |
User-agent: | Telnet/1.0 [tlh] (PDP11/DEC) |
Le 11/12/2020 à 14:28, Oğuz écrivait :
Nah, this doesn't work either. Would be really useful if it did though. $ declare -a foo=(1 2 ) $ declare -A assoc=("${foo[@]}" 3) $ declare -p assoc declare -A assoc=(["\"\${foo[@]}\""]="3" )
What would have been so useful is expanding mapfile to associative arrays: key${IFS}value declare -A assoc IFS='= ' mapfile -t assoc <<INFILE key1 = value1 key2=value2 with spaces INFILE And some dream of mapping JSON object members to associative arrays: mapfile -j assoc <<JSON { "key1": "value1", "key2": 42, "key3": { "otherkey": "othervalue" } } JSON translated to:declare -A assoc(["key1"]="value1" ["key2"]="value2" ["key3"]=$'{\n "otherkey": "othervalue"\n}'
-- Léa Gris
[Prev in Thread] | Current Thread | [Next in Thread] |