Dereferencing variable in loop

Hi ,

I have below code

While running above code i am receiving error : bad substitution

I need to use the variable s RC_1, RC_2 and their value outside of the loop.

Can anybody help me on that

correct:

echo "$RC_${i}"

What's your system? What's your shell?

You can do

VARNAME="asdf"

echo "${!VARNAME}"

on BASH and some KSH.

Hi,

Its a bash shell..

Have you corrected?

h5p:/home/vbe $ bash
h5p:/home/vbe $ test001
++ i=1
++ '[' 1 -le 2 ']'
++ eval RC_1=102
+++ RC_1=102
++ echo 1
+++ expr 1 + 1
++ i=2
++ '[' 2 -le 2 ']'
++ eval RC_2=102
+++ RC_2=102
++ echo 2
+++ expr 2 + 1
++ i=3
++ '[' 3 -le 2 ']'

Needs another eval to defer Shell interpreting the line until after the value of $i is known.

set -x
i=1
while [ $i -le 2 ]
do

eval RC_${i}=102
eval echo "\${RC_$i}"
i=`expr $i + 1`
done >> abc_log