Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

Variable value not getting printed

Shell Programming and Scripting


Closed Linux or Unix Question    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 01-04-2013
abhi1988sri abhi1988sri is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 18 October 2013, 2:42 AM EDT
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
Variable value not getting printed

Hi,

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


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

output:

Code:
r1
r2
r3
r4

also tried


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

output:

Code:
1
2
3
4

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

Regards

Abhinav

Last edited by Scott; 01-04-2013 at 07:58 AM.. Reason: Code tags, please...
Sponsored Links
    #2  
Old Unix and Linux 01-04-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 1 September 2015, 1:18 PM EDT
Location: Chennai
Posts: 573
Thanks: 50
Thanked 75 Times in 73 Posts
In your code


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 Linux
Sponsored Links
    #3  
Old Unix and Linux 01-04-2013
abhi1988sri abhi1988sri is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 18 October 2013, 2:42 AM EDT
Posts: 26
Thanks: 2
Thanked 0 Times in 0 Posts
there is a variable r1=10..Linux

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

Done with this...


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

Thanks

Last edited by Scott; 01-04-2013 at 07:59 AM.. Reason: Code tags
Sponsored Links
Closed Linux or Unix Question

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Need to limit the status printed anandek Shell Programming and Scripting 1 09-26-2012 09:38 AM
Value printed by gdb does not consist with the right value 915086731 Programming 1 10-17-2011 06:18 AM
Messages printed in the shell mregine UNIX for Dummies Questions & Answers 7 09-08-2011 01:07 AM
lp - order of files printed mabrownawa UNIX for Advanced & Expert Users 2 02-16-2004 11:08 AM



All times are GMT -4. The time now is 03:46 AM.