Bash: Variable substitution in variable name with default value
- by krissi
i have the following variables:
# config file
MYVAR_DEFAULT=123
MYVAR_FOO=456
#MYVAR_BAR unset
# program
USER_INPUT=FOO
TARGET_VAR=<need to be set>
If the USER_INPUT is "foo", I want TARGET_VAR to be the value of MYVAR_FOO (TARGET_VAR=456). If USER_INPUT is "bar" I want TARGET_VAR to be set to MYVAR_DEFAULT (123), because MYVAR_BAR is…