LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 01-11-2013, 01:40 AM   #1
tusharsharma43
LQ Newbie
 
Registered: Jan 2010
Location: Vadodara, Gujarat
Distribution: Fedora 17, OpenSuse, Ubuntu, Mint and Debian
Posts: 19

Rep: Reputation: 0
Smile 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
 
Old 01-11-2013, 01:46 AM   #2
pan64
Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 5,149

Rep: Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364Reputation: 1364
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
 
1 members found this post helpful.
Old 01-11-2013, 03:56 AM   #3
tusharsharma43
LQ Newbie
 
Registered: Jan 2010
Location: Vadodara, Gujarat
Distribution: Fedora 17, OpenSuse, Ubuntu, Mint and Debian
Posts: 19

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by pan64 View Post
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] ksh read variable from text file and populate with content of shell variable WindozBytes Programming 4 09-17-2012 02:48 PM
Need help with script writing: Storing cmd in variable, print variable, then exe cmds Arodef Programming 3 01-17-2012 01:26 AM
problem while comparing awk field variable with input variable entered using keyboard vinay007 Programming 12 08-23-2011 01:44 AM
[SOLVED] storing grep output to feed awk to retrieve entire records matching variable chargaff Programming 8 08-13-2010 07:10 AM
AWK a variable Ouptut to a new variable and using the new variable with the old one alertroshannow Linux - Newbie 4 02-16-2009 01:08 AM


All times are GMT -5. The time now is 10:50 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration