0

If I have 2 variables with values assigned as below -

a=1; s1=555

Can we print 555 using:

$ echo $s`echo $a`

...? My requirement is use variable 'a' in second variable to print final value of s1.

I have tried it already and failed. Is there any way?

Thanks.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278

1 Answers1

0

Bash has native syntax for indirect evaluation support:

a=1
s1=555

varname="s$a"
echo "${!varname}"
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441