bash: Indexed array and associative array.



  • Take into account the main readme for this section. README first.

    Index array, the array is indexed by numbers.

    $ declare -a garden=(roses buttercup iris)
    $ echo "${garden[0]}"
    roses
    $ echo "${garden[1]}"
    buttercup
    $ echo "${garden[2]}"
    iris
    

    Associative array, the array is indexed by any string.

    $ declare -A my_garden=([flower1]=roses [flower2]=buttercup [flower3]=iris)
    $ echo "${my_garden[flower1]}"
    roses
    $ echo "${my_garden[flower2]}"
    buttercup
    $ echo "${my_garden[flower3]}"
    iris
    

Log in to reply
 

© Lightnetics 2024