Passing Variables

I have below data:

DAY1=10202013

I am trying below but not getting the desired output:

COUNT=1
DATE=DAY$COUNT
echo "Date is $DATE"

However output I am getting is:

Date is DAY1

I wanted the output as:

Date is 10202013

I tried following as well:

DAY1=10202013
COUNT=1
DATE=${DAY$COUNT}
echo "Date is $DATE"

But its also throwing an error.

[user@host ~]$ DAY1=10202013
[user@host ~]$ COUNT=1
[user@host ~]$ eval DATE=\$DAY$COUNT
[user@host ~]$ echo $DATE
10202013
[user@host ~]$
1 Like

wow.. that was so simple... Thank you soooo much..

And if the contents of that variable had been `rm -Rf ~/` instead, you'd be mourning all the files your eval just deleted. Or less extremely, if it had a ` or $ in it, your program would crash with a mysterious syntax error as it tried to evaluate them as variables or backticks.

If you have BASH there's a much better way:

ASDF="12345"
VARNAME="ASDF"
echo "${!VARNAME}"