I would like to make a bash script that will take 3 different variables and return just one based on the setting of another. So if
TESTA_HOST=test1.google.com
TESTB_HOST=test2.google.com
TESTC_HOST=test3.google.com
M_INDEX=2
We want to search for all env variables that end in _HOST make an array that we can then use to compare to an index.
HOSTS="$(compgen -A variable | grep _HOST)"
export MAIN_URI="${HOSTS[M_INDEX]}"
echo $MAIN_URI
Expected output would be test3.google.com this doesn't work though since it is just returning the variable name and not the variable contents. What am I missing here?