Indirect variable assignment

Hi

I have variable A_B=alpha
also var1="A"
var2="B"

I want to retrieve the value alpha using var1 and var2 , somthing like
echo ${${var1}_${var2}} that works. Obviously this is receiving syntax
error

Use this:

$ A_B=alpha
$ var1="A"
$ var2="B"
$ eval echo \${${var1}_${var2}}
alpha

try with eval:

eval echo \${${var1}_${var2}}
V=${var1}_${var2}
$ echo ${!V}

In which shell should this work? I tried it with

  • bash ... empty output
  • ksh ... bad substitution
  • zsh ... prints "A_B"

:confused:

Works in bash from version 2

Strange, it works now, but it did not work the first time I tried (empty output). Must have mistyped something.

Anyway, thanks for the clarification.