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
# 1  
Old 10-02-2008
Error Exporting Value of a Variable as a Variable

Here's how;
Say;
I have a variable VAR which contains something like MY_DIR=/apphome/some/mydir.

What I want is I want to export VAR so that it will vitually export MY_DIR. Please suggest me?
# 2  
Old 10-02-2008
Error Additional Info

I'm using ksh. I did like this
Code:
export $VAR

but it keeps on saying "is not an identifier"
# 3  
Old 10-02-2008
The syntax is export VAR without a dollar sign.
# 4  
Old 10-02-2008
Thanks! But echoing $MY_DIR returns nothing.
# 5  
Old 10-02-2008
>export VAR=/dev/null
while using this environmental variables you have to use $VAR.

i am not clear some places i saw that assigning a env var with colon ':'
export PATH=/usr/bin:/usr/ucb:/etc:/usr/sbin:.:/usr/platform/sun4u/sbin

here you can find : and a . and again :
could some one explain this
# 6  
Old 10-02-2008
The colon doesn't matter from the shell's point of view at all. When the value of the variable contains multiple fields, you need to decide on a field separator. For variables which contain lists of paths, the colon is often picked as the field separator.

Please start a new thread unless your question is a direct follow-up to the current topic.
# 7  
Old 10-02-2008
Actually, there is nothing to do with the path. I am making a shell script that reads values from a properties file. So, in properties file, I put like that;
MY_DIR=/apphome/some/mydir. I read them with egrep. I got the whole string and I don't know what to do the rest Smilie. Any alternative? (Sorry if my post changes to another topic) I really need urgently.
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