Variable value not getting printed | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Variable value not getting printed

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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 08:58 AM.. Reason: Code tags, please...
Sponsored Links
    #2  
Old 01-04-2013
PikK45 PikK45 is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 26 November 2014, 5:10 AM EST
Location: Chennai
Posts: 567
Thanks: 43
Thanked 74 Times in 72 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
Sponsored Links
    #3  
Old 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..

---------- 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 08:59 AM.. Reason: Code tags
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 10:38 AM
Value printed by gdb does not consist with the right value 915086731 Programming 1 10-17-2011 07:18 AM
Messages printed in the shell mregine UNIX for Dummies Questions & Answers 7 09-08-2011 02:07 AM
lp - order of files printed mabrownawa UNIX for Advanced & Expert Users 2 02-16-2004 12:08 PM



All times are GMT -4. The time now is 05:38 PM.