Associative arrays (hash, dictionary) on bash

This is how to create associative arrays (hash, dictionary) on bash:

This script was made to purge the varnish on one of my clusters. But the important stuff is the declaration of the associative array with  DOMAINS['LIVE']=""; and how to access the values of the array (with  REQUEST_DOMAIN=${DOMAINS["$1"]};). “$1” is the array key to select the value.
By the way, you can see how to crate a multi-line array (STORES) and how to run through it within a foreach loop ( for sStore in ${STORES[@]} do [...] done; ).

Leave a Reply

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.