The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
comparing values of same variable coolkid Shell Programming and Scripting 2 05-27-2008 06:45 PM
getting values from variable in a loop kriuz Shell Programming and Scripting 3 01-22-2008 05:50 PM
assigning values to a variable trichyselva UNIX for Dummies Questions & Answers 3 12-14-2007 01:55 AM
Dynamic Variable Declatation Cameron Shell Programming and Scripting 2 09-26-2007 12:59 PM
Substitute variable values John Rihn Shell Programming and Scripting 12 03-15-2006 10:40 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-11-2008
ronnie_uk ronnie_uk is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 16
Dynamic variable values

Bit of a newbie with regard to unix scripting and need some advice. Hopefully someone can help with the following:

I have a predefined set of variables as follows:

AAA_IP_ADD=1.1.1.1
BBB_IP_ADD=2.2.2.2

I have a funnction call which retrieves a value into $SUPPLIER which would be used as a prefix to obtain the IP address for a specific SUPPLIER. The function works and returns me a value but for explanation purposes it could be defined as follows:

$SUPPLIER=BBB

I need to now retreive the value from AAA_IP_ADD or BBB_IP_ADD based on the setting for $SUPPLIER.

So I concatenate '_IP_ADD' onto $SUPPLIER. To try and make sense of it here is what I am trying to run:

echo $SUPPLIER'_IP_ADD'

This returns a literal value and not the value stored in AAA_IP_ADD or BBB_IP_ADD

Can anyone advise how I get the actual value for these variables.

Thanks

Last edited by ronnie_uk; 07-11-2008 at 08:43 AM..
  #2 (permalink)  
Old 07-11-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,941
One way ...

Code:
AAA_IP_ADD="1.1.1.1"
BBB_IP_ADD="2.2.2.2"

SUPPLIER="BBB"

eval IPADDR='$'{${SUPPLIER}_IP_ADD}
echo $IPADDR

  #3 (permalink)  
Old 07-11-2008
ronnie_uk ronnie_uk is offline
Registered User
  
 

Join Date: Jul 2008
Posts: 16
Fantastic, thank you very much.
  #4 (permalink)  
Old 07-11-2008
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Moderator
  
 

Join Date: Dec 2003
Location: Florida
Posts: 1,941
BTW, if you are using ksh93, another way to do what you want to do is to use a nameref i.e.

Code:
#!/bin/ksh93

AAA_IP_ADD="1.1.1.1"
BBB_IP_ADD="2.2.2.2"

SUPPLIER="BBB"

nameref IPADDR=${SUPPLIER}_IP_ADD
print $IPADDR

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:09 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0