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
Sed variable substitution when variable constructed of a directory path alrinno Shell Programming and Scripting 2 07-11-2008 03:24 PM
KSH variable substitution tipsy Shell Programming and Scripting 5 08-14-2006 06:07 PM
Variable Substitution garak Shell Programming and Scripting 2 03-16-2006 08:55 PM
awk variable substitution apalex UNIX for Dummies Questions & Answers 1 09-10-2004 07:02 PM
Substitution in a variable spragueg UNIX for Advanced & Expert Users 3 10-18-2001 10:14 AM

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 10-17-2008
Leo_NN Leo_NN is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 34
Variable substitution

Hi,

That might be pretty simple.
How can I generate a variable name and get their value ?

Thanks a lot.

Something like:

>CUSTOMER_NF=26
> object=CUSTOMER

> echo ${object}_NF
CUSTOMER_NF

> echo ${${object}_NF}
ksh: ${${object}_NF}: 0403-011 The specified substitution is not valid for this command.

> echo $`echo ${object}_NF`
$CUSTOMER_NF
  #2 (permalink)  
Old 10-17-2008
joeyg's Avatar
joeyg joeyg is offline Forum Staff  
modérateur
  
 

Join Date: Dec 2007
Location: Home of 17-time world champion Boston Celtics
Posts: 1,311
Wink One format


Code:
> cust_num=2026
> echo "$cust_num"
2026
>

  #3 (permalink)  
Old 10-17-2008
Leo_NN Leo_NN is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 34
Thanks,
but that's not it.

I need dynamically generate and substitute part of the variable name.

object=cust
echo $cust_num

object=policy
echo $policy_num

echo ${$object}_num????
etc...
  #4 (permalink)  
Old 10-17-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926

Code:
$ CUSTOMER_NF=26
$ object=CUSTOMER
$ eval echo \$${object}_NF
26

  #5 (permalink)  
Old 10-17-2008
Leo_NN Leo_NN is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 34
Quick and easy!

Thanks as always!!!
  #6 (permalink)  
Old 10-17-2008
Leo_NN Leo_NN is offline
Registered User
  
 

Join Date: Sep 2008
Posts: 34
hi again,

how should I use correctly:

Quote:
> i_var=26
> eval echo \$${object}_NF
26


> if [[ i_var == `eval echo \$${object}_NF` ]]
> then
> echo OK
> else
> echo "NOT OK"
> fi
NOT OK
> if [[ i_var -eq `eval echo \$${object}_NF` ]]
> then
> echo OK
> else
> echo "NOT OK"
> fi
NOT OK
>
  #7 (permalink)  
Old 10-17-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,926

Code:
CUSTOMER_NF=26
object=CUSTOMER
eval "tmp=\$${object}_NF"
case $tmp in
  26 ) print OK;;
   * ) print KO;;
esac

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 04:38 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