dynamically creating a variable name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting dynamically creating a variable name
# 1  
Old 05-31-2005
Data 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
# 2  
Old 05-31-2005
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
# 3  
Old 05-31-2005
that worked...thank you Thomas :-)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Dynamically changing environment variable

Linux Redhat, BASH Shell. I want to put this in my .bash_profile I have log files that go to directory paths based in part on other variables such as went DB Name is set in memory. So if the DB Name changes the path to the log file changes. How do I create an environment variable I put into... (6 Replies)
Discussion started by: guessingo
6 Replies

2. Shell Programming and Scripting

Creating IN list in PLSQL script dynamically by using shell script

Hi all, I have a PLSQL script which has a IN list where it takes some ids as input. For example SELECT * FROM EMPLOYEE WHERE EMPLOYEE_ID IN (comma separated list ) I want to run this quest inside a shell script but I would like to prepare the IN list dynamically where the employee ids... (1 Reply)
Discussion started by: LoneRanger
1 Replies

3. Programming

Dynamically creating structure in C/C++ program

Hi, For one of the project which i am working on i need to write a cpp code such that it will create the structure dynamically instead of reading it from header file. For example we have a program which is reading a binary file according to the structure mentioned in header file. But we... (0 Replies)
Discussion started by: AmbikaValagonda
0 Replies

4. Shell Programming and Scripting

Creating variables dynamically and using it in script?

Hi, I have a problem that I am trying to solve and would greatly appreciate some input to solve this. I have a file containing variable length of line. Each line in the file has values separated by "," and i need to grep for these values in a some files. For example below is a sample file with 3... (12 Replies)
Discussion started by: davidtd
12 Replies

5. Shell Programming and Scripting

Shell script variable names created dynamically

Hi, I'm trying to use a config file to define frequencies for checking log files. If the config file contains a frequency it will be used else a default value. The format of the config file (and hence the environment variable) is FREQ_log_logname=value A test shell script as below:... (2 Replies)
Discussion started by: u671296
2 Replies

6. Shell Programming and Scripting

Dynamically setting of environment variable... Can it be done?

Hi all, I am fairly new to unix scripting and will like to know how to dynamically set the name of an environment variable to be used. We have a .env file where we defined the names and locations of data files, trigger files, directories .... etc Example of variables defined in .env... (4 Replies)
Discussion started by: Morelia
4 Replies

7. Shell Programming and Scripting

BASH - Reference external variable name dynamically

Hi there, I have included an external properties file into my BASH script via the 'source' command. I am attempting to dynamically assign a variable in the BASH script, that references the variable name within the external properties file i.e. #!/bin/bash pth=${0%/*} source... (3 Replies)
Discussion started by: mjwoodford
3 Replies

8. Shell Programming and Scripting

Adding string variable dynamically in for loop

Hi, I need to generate the text name dynamically in for loop, ex, VAR_COPY_FILE1= file path 1 VAR_COPY_FILE2= file path 2 VAR_COPY_FILE3= file path 3 for i in 1 2 3 do if then "do some process here" fi done (3 Replies)
Discussion started by: msubash26
3 Replies

9. Shell Programming and Scripting

Dynamically creating text files using shell script

Hi All, I want to create a shell script which dynamically create text files. i am using the following script $i=1 while do cat > test_$i.txt done but while running the script it was stopping(the cursor not going to next step, i have to enter ctrl+c to make it stop). it is creating only... (2 Replies)
Discussion started by: KiranKumarKarre
2 Replies

10. Shell Programming and Scripting

Dynamically Creating and Printing to Files

Hello, If anyone could help me out with this, it would be greatly appreciated. I am trying to dynamically create files and print to them. Here is the code I have to so far. thanks. if (n < 5000 ) { # do nothing } else { n = 0; filenum++; # out = ("out" filenum); } ... (1 Reply)
Discussion started by: Laud12345
1 Replies
Login or Register to Ask a Question