Know the boring details already and just want the answer?
EVAL=$(eval echo -n \$${VAR})
Otherwise read on...
This took me longer than it normally does to look something up in the man page, so I may as well share it in case others have the same need in writing a shell script...
Variable-variables, for those that don't know, are variables that you'd like resolved not once, but twice. For example...
foo=bar
bar=zap
The first resolution of foo (i.e. $foo), would give the value bar. The second resolution of foo (i.e $$foo) would give the first resolution of bar (i.e. $bar), which is zap. While this double-dollar syntax is exactly how you'd do this in a language like PHP, it's a little more annoying in Bash.
Here's an example where I need to check for a to see if all elements in a list have been set...
EXIT=0
for VAR in GIT_BASE SVN_BASE; do
EVAL=$(eval echo -n \$${VAR}) #. Double-resolve
if [ -z "${EVAL}" ]; then #. $VAR not set?
EXIT=$((${EXIT} + 1)) #. Increment EXIT
fi
done
exit ${EXIT}
So if GIT_BASE and SVN_BASE are both set, EXIT will hold a value of 0, if none are set, it will hold 0, and so on.