LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Howto retrieve value of variable within variable (https://www.linuxquestions.org/questions/linux-general-1/howto-retrieve-value-of-variable-within-variable-4175445087/)

tusharsharma43 01-11-2013 12:40 AM

Howto retrieve value of variable within variable
 
Hello All ,

Problem Description

A1=Hello
A2=World
A3
.
.
and so on
I want to print Values of All A1,A2

for (( i=0; i < 10; i++ ))
VAR = A$i;
do
echo $(A$i);
// echo $($VAR);

done

is not working.

Can Any one help me in retrieving value of variable within variable



Thanks & Regards
Tushar Sharma

pan64 01-11-2013 12:46 AM

you need to use eval, but first see here: http://www.linuxquestions.org/questi...al-4175426547/
Code:

for (( i=0; i < 10; i++ ))
do
    eval echo \$A$i;
done


tusharsharma43 01-11-2013 02:56 AM

Quote:

Originally Posted by pan64 (Post 4867547)
you need to use eval, but first see here: http://www.linuxquestions.org/questi...al-4175426547/
Code:

for (( i=0; i < 10; i++ ))
do
    eval echo \$A$i;
done


Okay Thanks a lot :), It was a great Help.
Also I was able to do same with help of associative array in shell script.


Thanks & Regards
Tushar Sharma


All times are GMT -5. The time now is 08:29 PM.