Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Exporting Environment Vars 3

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

On a Solaris 8 system in a Bourne shell script I want the user that runs a script (root) to have the environment settings that I set within my script...after the script has run.

My problem is that though I am exporting the variables in the script, after the script is run they are gone from the environment.

Code:
#!/bin/sh
ORACLE_SID=DB1; export ORACLE_SID
ORACLE_BASE=/usr1/home/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2; export ORACLE_HOME
LD_LIBRARY_PATH=$ORACLE_HOME/lib; export LD_LIBRARY_PATH

[COLOR=green]# When script run these look correct.[/color]
echo "ORACLE_SID:      $ORACLE_SID"
echo "ORACLE_BASE:     $ORACLE_BASE"
echo "ORACLE_HOME:     $ORACLE_HOME"
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"

Below however is my environment AFTER the script:
Code:
env

HOME=/
HZ=100
LOGNAME=root
PATH=/usr/sbin:/usr/bin:/usr/local/bin
SHELL=/sbin/sh
TERM=ansi
TZ=US/Eastern

What can you recommend?

Thanks,

Michael42
 
Have a look at the . (dot) command (aka source).

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
in your root directory, create or add to /.profile
ORACLE_HOME=/xxx/orabase/product/9.2.0;export ORACLE_HOME
ORACLE_SID=mydatabase;export ORACLE_SID
ORACLE_PATH=ORACLE_HOME;export ORACLE_PATH
LD_LIBRARY_PATH=$ORACLE_HOME/lib; export LD_LIBRARY_PATH

execute
. ./.profile
or sign-off/on

$ env|grep ORACLE
ORACLE_PATH=ORACLE_HOME
ORACLE_SID=mydatabase
ORACLE_HOME=/xxx/orabase/product/9.2.0

$env |gre LD
LD_LIBRARY_PATH=$ORACLE_HOME/lib; export LD_LIBRARY_PATH
 
Even though you are exporting the variable, once the script exits, the
value will be erased because it is not passed back "up" the process tree.

If you run the script with a ".", it will perform as you expect.

# . ./yourscript

Mike

"A foolproof method for sculpting an elephant: first, get a huge block of marble, then you chip away everything that doesn't look like an elephant."

 
Guys,

I did not know that about using the dot. Thanks for the posts! :)

Michael42
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top