Exporting Value of a Variable as a Variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Exporting Value of a Variable as a Variable
# 8  
Old 10-02-2008
So what is it that you are trying to accomplish?

Your properties file contains this line, correct?

MY_DIR=/apphome/some/mydir

So, you want to have a shell script variable (MYVAR) to contain this?

If I then echo $VAR what do you want it to contain:

MY_DIR=/apphome/some/mydir
or
/apphome/some/mydir
# 9  
Old 10-02-2008
I want MY_DIR as a variable containing /apphome/some/mydir.

Thanks
# 10  
Old 10-02-2008
MY_DIR=/apphome/some/mydir
export MY_DIR
env
By running the env command you can check that it worked. But remember, if you put this in a script and then do:
exit 0
this script and the process running it will end and the environment is discarded. The env command above was a child process so it inherits MY_DIR. But you cannot set a parent process' environment.
# 11  
Old 10-02-2008
I think I didn't make it clear. Sorry.
Actually, MY_DIR=/apphome/some/mydir is containted in a variable, VAR. That's why.
# 12  
Old 10-03-2008
So if you eval $VAR then the effect should be to set MY_DIR to the value after the equals sign.
# 13  
Old 10-03-2008
could you please give the complete line of the assigning the value to the variable VAR.
this is new to me so i want to know how you are assigning and how to use eval command.

sorry for my interruption. i want to learn thats why.
Thanks.
# 14  
Old 10-03-2008
Code:
vnix$ VAR="MY_DIR=/path/to/where-ever"
vnix$ eval $VAR
vnix$ echo $MY_DIR
/path/to/where-ever

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] How to increment and add variable length numbers to a variable in a loop?

Hi All, I have a file which has hundred of records with fixed number of fields. In each record there is set of 8 characters which represent the duration of that activity. I want to sum up the duration present in all the records for a report. The problem is the duration changes per record so I... (5 Replies)
Discussion started by: danish0909
5 Replies

2. Shell Programming and Scripting

Problems setting or exporting variable when using multiple commands from same line.

I am experimenting with some scripting as a way to learn more about it. I have a simple script that calls two other scripts. Each script echos some stuff to prove it ran and then sets a simple variable and exports it. I cannot get one of the variables to display back in the main calling script... (2 Replies)
Discussion started by: scottrif
2 Replies

3. Red Hat

How to pass value of pwd as variable in SED to replace variable in a script file

Hi all, Hereby wish to have your advise for below: Main concept is I intend to get current directory of my script file. This script file will be copied to /etc/init.d. A string in this copy will be replaced with current directory value. Below is original script file: ... (6 Replies)
Discussion started by: cielle
6 Replies

4. Shell Programming and Scripting

Export command variable exporting problem

I have a txt file from which i am assiging a value to a variable using the code in script1 script1.sh export f=$(sed -n "/Freq *=/ s/.*= *//p" ${R_path}/output.txt) echo "$f" --------> this works in script2 ( which executes the script1) eval ./script1.sh if && ; then echo... (1 Reply)
Discussion started by: shashi792
1 Replies

5. Shell Programming and Scripting

exporting variable

Hi All; I m working on a script and came across an issue ,to explain it briefly here is the sample code echo $HOSTNAME|while read IN; do var=`echo $IN|awk -F "-" '{print $2}'`; export var; echo $var; done now I get the value of $var but when it is out of the while loop it does not return... (3 Replies)
Discussion started by: maverick_here
3 Replies

6. Shell Programming and Scripting

Exporting my dynamical variable won't work?

Even though the idea "might" not be great I still wrote this piece of code to get practice.. Which means that it is the CODE that matters here. Anyways; The intension is to create a program(or do we call it script?) that searches recursively through a folder to find a file - stored in a... (4 Replies)
Discussion started by: Pesk
4 Replies

7. Shell Programming and Scripting

How to define a variable with variable definition is stored in a variable?

Hi all, I have a variable say var1 (output from somewhere, which I can't change)which store something like this: echo $var1 name=fred age=25 address="123 abc" password=pass1234 how can I make the variable $name, $age, $address and $password contain the info? I mean do this in a... (1 Reply)
Discussion started by: freddy1228
1 Replies

8. Shell Programming and Scripting

Insert a line including Variable & Carriage Return / sed command as Variable

I want to instert Category:XXXXX into the 2. line something like this should work, but I have somewhere the wrong sytanx. something with the linebreak goes wrong: sed "2i\\${n}Category:$cat\n" Sample: Titel Blahh Blahh abllk sdhsd sjdhf Blahh Blah Blahh Blahh Should look like... (2 Replies)
Discussion started by: lowmaster
2 Replies

9. Solaris

variable exporting

Hi, can anyone tell me the difference between the below two examples: Eg-1: # name=bravo # echo $bravo what would be the o/p Eg-2: # name1=jhonny # export name1 # echo $name1 what would be the o/p If the o/p's of both examples are the same then what is the use of the cmd export... (3 Replies)
Discussion started by: rahul_11d
3 Replies

10. Shell Programming and Scripting

Exporting variable from config file

Hi, I am exporting the environment variable from config file, but when I echo the variable it does not display any value. Here is the snippet of the code #!/bin/sh export ENVIRONMENT_ROOT_DIRECTORY="/cb/$ENVIRONMENT" echo $ENVIRONMENT_ROOT_DIRECTORY ${JAVA_HOME}/bin/java... (2 Replies)
Discussion started by: bhavnabakshi
2 Replies
Login or Register to Ask a Question