variable substitution in ksh

Hi
I have a variable BIT1 which holds some value. Is there a way to retrieve the value of this variable indirectly via another variable, lets say SUBSET_BIT_NUM=1, so the call will look something like this:

sundev1 $ echo ${BIT${SUBSET_BIT_NUM}}
ksh: ${BIT${SUBSET_BIT_NUM}}: bad substitution

Thanks a lot for any advice -A

#!/bin/ksh

BIT1=aoussenko
BIT2=foo

SUBSET_BIT_NUM=1

eval echo \${BIT${SUBSET_BIT_NUM}}

The following also works

eval echo '${BIT'${SUBSET_BIT_NUM}'}'

That's not very reliable:

  BITTER=qwerty
  SUBSET_BIT_NUM=TER
  IFS=E
  eval echo '$BIT'$SUBSET_BIT_NUM  ## unreliable
  eval echo "\$BIT$SUBSET_BIT_NUM" ## correct

The output is:

R
qwerty
1 Like