Multidimensional associative arrays in Bash

前端 未结 3 1835
耶瑟儿~
耶瑟儿~ 2020-12-05 02:52

I\'m trying to create a multidimensional associative array but need some help. I have reviewed the page suggested in this SO answer but it confused me even more. So far here

3条回答
  •  没有蜡笔的小新
    2020-12-05 03:35

    #!/bin/bash
    declare -A PERSONS
    declare -A PERSON
    PERSON["FNAME"]='John'
    PERSON["LNAME"]='Andrew'
    PERSONS["1"]=${PERSON[@]}
    PERSON["FNAME"]='Elen'
    PERSON["LNAME"]='Murray'
    PERSONS["2"]=${PERSON[@]}
    for KEY in "${!PERSONS[@]}"; do
     TMP="${PERSONS["$KEY"]}"
     echo "$KEY - $TMP"
     **echo "${PERSON["FNAME"]}"
     echo "${PERSON["LNAME"]}**"
    done
    

    Because the original array for the separate names is still active and it can still be referenced within the for loop.

提交回复
热议问题