Lazy create associative array-like construction in Bash
This scripts work on Bash.
Tested on RHEL 7, Ubuntu 14.04, 16.04
#!/bin/bash set -e 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
That's all, folks!
Tweet