0

I am phrasing variables in shell script and expecting some value but shows another value, example shows as below:

export var_a_b="12345"
var_a="a"
var_b="b"
echo ${var_a_b} # Output: 12345 (shows properly)

new_var_a_b="var_${var_a}_${var_b}"
echo $new_var_a_b # Output: var_a_b (But I am expecting actual value of var_a_b i.e 12345)

Can someone help me on where I am placing wrong.

Ku002
  • 117
  • 1
  • 2
  • 14

1 Answers1

1

You need parameter indirection:

$ a=b
$ b=c
$ echo "${!a}" # c
Andreas Louv
  • 46,145
  • 13
  • 104
  • 123