Let's say I have these variables:
VAR_A=resultA
VAR_B=resultB
X=A
I want to get the value of VAR_A
or VAR_B
based on the value of X
.
This is working and gives resultA
:
VAR="VAR_$X"
RESULT=${!VAR}
My question is, is there a one-liner for this?
Because indirection expansion doesn't seem to work if it is not the wole name of the variable which is expanded. I tried:
RESULT=${!VAR_$X}
RESULT=${!"VAR_$X"}
...and a lot of other combinations, but it always write "bad substitution"...