On 12/11/20 9:45 AM, Léa Gris wrote:
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:

This is an interesting idea for a future bash version.


     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

But I'm not really interested in writing a JSON parser and integrating it into mapfile. Maybe someone would be interested in writing a loadable
builtin, along the lines of the `csv' loadable builtin in bash-5.1.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    c...@case.edu    http://tiswww.cwru.edu/~chet/

Reply via email to