Dynamic variable values

Bit of a newbie :smiley: with regard to unix scripting and need some advice. Hopefully someone can help with the following:

I have a predefined set of variables as follows:

AAA_IP_ADD=1.1.1.1
BBB_IP_ADD=2.2.2.2

I have a funnction call which retrieves a value into $SUPPLIER which would be used as a prefix to obtain the IP address for a specific SUPPLIER. The function works and returns me a value but for explanation purposes it could be defined as follows:

$SUPPLIER=BBB

I need to now retreive the value from AAA_IP_ADD or BBB_IP_ADD based on the setting for $SUPPLIER.

So I concatenate '_IP_ADD' onto $SUPPLIER. To try and make sense of it here is what I am trying to run:

echo $SUPPLIER'_IP_ADD'

This returns a literal value and not the value stored in AAA_IP_ADD or BBB_IP_ADD

Can anyone advise how I get the actual value for these variables.

Thanks

One way ...

AAA_IP_ADD="1.1.1.1"
BBB_IP_ADD="2.2.2.2"

SUPPLIER="BBB"

eval IPADDR='$'{${SUPPLIER}_IP_ADD}
echo $IPADDR

Fantastic, thank you very much.

BTW, if you are using ksh93, another way to do what you want to do is to use a nameref i.e.

#!/bin/ksh93

AAA_IP_ADD="1.1.1.1"
BBB_IP_ADD="2.2.2.2"

SUPPLIER="BBB"

nameref IPADDR=${SUPPLIER}_IP_ADD
print $IPADDR