Variable value not getting printed

Hi,

I ma trying to do this but don't know why it is not happening?

$r1=10
 
for i in "1" "2" "3" "4"; do x=`eval echo $i`; echo r${x}; done

output:

r1
r2
r3
r4

also tried

for i in "1" "2" "3" "4"; do x=`eval echo $i`; echo $r${x}; done

output:

1
2
3
4

why I am not able to get the value of r1...Where I am geting wrong?

Regards

Abhinav

In your code

for i in "1" "2" "3" "4"; do x=`eval echo $i`; echo $r${x}; done

There is no such variable called "r". Highlighted above :slight_smile:

there is a variable r1=10..:slight_smile:

---------- Post updated at 05:58 PM ---------- Previous update was at 05:32 PM ----------

Done with this...

 for i in "1" "2" "3" "4"; do eval echo \${r${i}}; done

Thanks