0
FontName=Ubuntu
FontSize=300
let $FontName$FontSize=21

Getting the value is easy using the following:

echo $Ubuntu300
21

However, how can I get the same result using variables?

I tried something like:

echo ${!FontName!FontSize}

but no luck, I hope I am at least close!

TuxForLife
  • 219
  • 1
  • 2
  • 15

2 Answers2

1

You have to assign your new dynamic variable to a new one, like this:

var=$FontName$FontSize

Then use indirect parameter expansion to get its value:

echo ${!var}

Will output 21

higuaro
  • 15,730
  • 4
  • 36
  • 43
1

You may want to try this :

FontName=Ubuntu
FontSize=300
let ${FontName}${FontSize}=21

echo $Ubuntu300
21

For curiosity, instead of assigning new variable :

echo $((${FontName}${FontSize}))
21
jderefinko
  • 647
  • 4
  • 6
  • jderfinko, I think you meant `echo $((${FontName}${FontSize}))` However, that worked, and I got the expected result! Thank you, I was also curious if it was possible to do without assigning a new variable – TuxForLife Mar 18 '15 at 15:36