1

I want to be able to take the values of two variables and concatenate them together to form the identifier for another variable in a bash script.

  final_answer="we did it"
  one="final"
  two="answer"
  t="${one}_${two}"
  echo ${$t} # would like this to echo we did it; currently give "${$t}: bad substitution"

Not sure this is possible but it seems like bash would have this capacity somehow.

Thank you!

J. LaF
  • 127
  • 9

1 Answers1

1
$ echo "${!t}"
we did it

See http://mywiki.wooledge.org/BashFAQ/006#Indirection for details.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185