Operating System - HP-UX
1829636 Members
1657 Online
109992 Solutions
New Discussion

updating a environment var without re-exporting it

 
Daryl Much
Frequent Advisor

updating a environment var without re-exporting it

Folks,

In posix shell, Is there a way to have an environment variable inherit the value of another variable as it changes? i.e., if

export VAR1=/foo/bar
and
export VAR2=$VAR1
then
$VAR2=/foo/bar

if VAR1 changes then I need to re-export VAR2 to get the new value and I don't want to do that.

I'm looking for a way that works similar to PS1, which will inherit changes.

What I'm really trying to do is set up a bunch of different oracle environments that will change based on the value of SID and ORACLE_HOME. The only way I can think of involves aliases and each of these is getting very long.

Thanks,

Chuck Davis
3 REPLIES 3
Leif Halvarsson_2
Honored Contributor

Re: updating a environment var without re-exporting it

Hi,
I don't belive this is possible without starting a new shell (and use a ENV file).
Biswajit Tripathy
Honored Contributor

Re: updating a environment var without re-exporting it

I'm not sure if there is a way to automatically
change VAR2 when VAR1 changes. One
"workaround" would be to write a function which
resets VAR2 and should be called everytime you
modify VAR1. Something like:

reset_var ()
{
VAR2=$VAR1
}

VAR1="str1";reset_var

.. your script here

VAR1="str2";reser_var

.. some more of your ascript here...

- Biswajit
:-)
Daryl Much
Frequent Advisor

Re: updating a environment var without re-exporting it

thanks for the input. It was as I suspected. to keep it simple for the users I ended up writing an alias that calls a function and also sets/clears some environment variables.

fwiw, it goes like this:

ora_env () #this function is run each time the SID alias (defined below) is invoked
{
export ORACLE_BASE=${ORA_APP}/admin
export ORACLE_HOME=${ORA_APP}/product/${ORA_VER}
export SHLIB_PATH=${SHLIB_PATH}:${ORACLE_HOME}/lib32:/usr/lib
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:${ORACLE_HOME}/lib
unset SP_SYS_VARDIR
} #end function ora_env

alias mast='export ORACLE_SID=mast;\
export ORA_VER=9.0.1.0;\
export ORA_APP=/data0/app/oracle;\
ora_env
export SP_SYS_VARDIR=/data0/splex/var;\
export PATH=$PATH:/data0/splex/prod/bin'


alias ioct='export ORACLE_SID=ioct;\
export ORA_VER=9.0.1.0;\
export ORA_APP=/data0/app/oracle;\
ora_env'


alias mast21='export ORACLE_SID=mast21;\
export ORA_VER=9.0.1.0;\
export ORA_APP=/data0/app/oracle;\
ora_env'

alias prod='export ORACLE_SID=prod;\
export ORA_VER=8.1.7;\
export ORA_APP=/usr0/app/oracle;\
ora_env'


alias wrstest='export ORACLE_SID=wrstest;\
export ORA_VER=8.1.7;\
export ORA_APP=/usr0/app/oracle;\
ora_env'

---

This info is in a separate script that is sourced by /etc/profile. The user needs to only type the sid name and the variables will be set accordingly. Main drawback is the PATH can get redundant settings tacked to it. If this becomes a problem then I may throw a little sed in the function to clean it up.

Regards,

Chuck Davis