The lazy programmer scripts
scripts that work

Lazy create associative array-like construction in Bash

This scripts work on Bash.

Tested on RHEL 7, Ubuntu 14.04, 16.04

#!/bin/bash
ASSOC_ARRAY_KEYS=("KEY1", "KEY2")
KEY1_VAL="VAL1"
KEY2_VAL="VAL2"

for ASSOC_ARRAY_KEY in ${ASSOC_ARRAY_KEYS[@]}; do
    VAL_REF="${ASSOC_ARRAY_KEY}_VAL"
    echo "${!VAL_REF}"
    # It should print VAL1 and VAL2
done
Written by kami on Friday March 17, 2017
Permalink -

« Not found - Lazy create Windows NAT net adapter »