tamalsaha / learn-bash

0 stars 0 forks source link

Map / HashTable / Associate Array #13

Open tamalsaha opened 4 years ago

tamalsaha commented 4 years ago
tamalsaha commented 4 years ago

The values of an associative array are accessed using the following syntax ${ARRAY[@]}.

To access the keys of an associative array in bash you need to use an exclamation point right before the name of the array: ${!ARRAY[@]}.

To iterate over the key/value pairs you can do something like the following example

# For every key in the associative array..
for KEY in "${!ARRAY[@]}"; do
  # Print the KEY value
  echo "Key: $KEY"
  # Print the VALUE attached to that KEY
  echo "Value: ${ARRAY[$KEY]}"
done
tamalsaha commented 4 years ago

Map with Array Values

https://stackoverflow.com/a/41677801