variable part of variable name

Greetings

I am having a hard time trying to figure out how to use a variable as part of another variables name.

For instance:

A="PRE"
eval ${A}_DAY=`date +%d`
echo ${A}_DAY
echo $PRE_DAY

output:
PRE_DAY
25

I would appreciate some help with this.

Hi,

I'm not sure this answer suits to your request (if you meant
"how to display/store or use the resulting value", then this
should help...).

First, the 2 first lines sound correct for both defining a variable
and assigning a value to it:
me@host> A="PRE"
me@host> eval ${A}_DAY=`date +%d`

In order to solve this kind of trouble, I usually use this
kind of syntax:
me@host> DAY_VALUE=$(unalias echo; eval echo $"${A}_DAY")
me@host> echo ${DAY_VALUE}
me@host> 25

Hope it helps,
Christophe

Ran into a couple of other ways...

echo $(eval echo \$${A}_DAY)
eval echo "\$${A}_DAY"

Thank You for your answer :slight_smile: