Q:

echo $HOSTNAME result become key to a variable

Property
server1=abc,def,ghc
server2=xyz,tes,iuy
#!/bin/sh

echo $server1
abc,def,ghc

echo $HOSTNAME
server1

with those info above, I want to output the output "abc,def,ghc" in a test variable. 
echo \$$HOSTNAME
$server1

bash-4.1$ test=`echo \$$HOSTNAME`
bash-4.1$ echo $test
8722HOSTNAME

How can I get this done in perl/bash?

A:

man 1 bash says:
If the first character of parameter is an exclamation point (!), it introduces a level of variable indirection.  Bash uses the value of the variable formed from the rest of parameter as the name of the variable; this variable is then expanded and that value is used in the rest of the substitution, rather than the value of parameter itself.  This is known as indirect expansion.
$ server1=abc,def,ghc
$ HOSTNAME=server1
$ echo ${!HOSTNAME}
abc,def,ghc

