The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


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

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Creating a file in variable length format Sarahb29 UNIX for Dummies Questions & Answers 2 04-22-2008 08:07 AM
creating a variable rexmabry UNIX for Dummies Questions & Answers 3 02-22-2008 12:30 PM
creating array variable scriptingmani Shell Programming and Scripting 2 06-28-2007 07:25 AM
Dynamically Creating and Printing to Files Laud12345 Shell Programming and Scripting 0 03-02-2005 10:07 AM
creating a fixed length output from a variable length input r1500 Shell Programming and Scripting 2 12-03-2003 10:09 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 05-31-2005
Registered User
 

Join Date: May 2005
Posts: 2
Unhappy dynamically creating a variable name

Hi !

I have the following situation -

##First variable
variableA=JOB_A

##bunch of other variable
JOB_A_RESTART=cleanupJobA
JOB_B_RESTART=cleanupJobB
JOB_C_RESTART=cleanupJobC


now i need a script which would -

1. take the first variable
2. create a new variable name dynamically by appending "_RESTART" to the VALUE of the first variable.
for example if variableA=JOB_B then
the name of the new variable would be JOB_B_RESTART
3. give me the VALUE (not name) of the newly created variable. For example the value of JOB_B_RESTART would be cleanupJobB.

I have been able to reach so far as step 2 but i have not been able to get the value of the newly created variable.

My code is given below -

variableA=JOB_A
newVar=${variableA}_RESTART
echo $newVar

this last line echos "JOB_A_RESTART" whereas i want it to echo "cleanupJobA". Please helppppppppp ....

thanks
Reply With Quote
Forum Sponsor
  #2  
Old 05-31-2005
Registered User
 

Join Date: Jan 2005
Posts: 682
Here is my similar question where vgersh99 provided this answer:

Code:
#!/bin/ksh

x=TESTVAR2

eval export "${x}_stdout=3"

print $TESTVAR2_stdout

# results in print $TESTVAR2_stdout
eval "print \$${x}_stdout"
So, yours should equate to this:
Code:
eval "newVar=\$${variableA}_RESTART"
Thomas
Reply With Quote
  #3  
Old 05-31-2005
Registered User
 

Join Date: May 2005
Posts: 2
that worked...thank you Thomas :-)
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:11 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0