Variable within a Variable

I am having difficulty wrapping my head around this one, maybe it is just because it is Monday. Anyway, a DBA came to me and asked me a question on a script he is working on. In a very simple format here is what the meat of the problem is.

#/bin/sh
arg=$1
export monkey_21_test=910
export monkey_22_test=980
newvar=`echo \$monkey_${arg}_test`
echo $newvar

He wants to be able to have a variable at the top of his script that is always changing, perhaps multiples that he can add with a certain value. Then depending on an argument from the command line he calls a particular variable. In the above exampe he wants the 980 to return when he puts in 22. His script actually has multiple arguments. Is there a way to do this using the method he is trying? We can get it to return $monkey_22_test or $monkey_21_test. I am drawing a blank here, mostly because I never tried to throw around a variable value this way.

Basically he is trying to make the script other than the beginning as dynamic as possible. But the beginning export of variables will be ever changing with new names. Thanks in advance.

Try somethoing like that :

#/bin/sh
arg=$1
export monkey_21_test=910
export monkey_22_test=980
newvar=monkey_${arg}_test
eval echo \$newvar

Jean-Pierre.

Thank you sir, escaping the $ in the variable definition worked and then using eval. I thank you for slapping me in the head and clearing the cobwebs.

export arg=$1
export monkey_21_test=910
export monkey_22_test=980
newvar=\$monkey_${arg}_test

eval echo $newvar