09-24-2001 10:26 PM - last edited on 11-22-2012 07:33 PM by Cathy_xu
when i execute a shell command file,in that file i set some enviroment variables and exports them,it works right when it's being executed.
but when the shell file is over,that exported enviroment variables dispear also.
if i execute the file using " . filename ",
it do what i want,that is why??
P.S.This thread has been moved from HP-UX >General to HP-UX > languages- HP Forums Moderator
09-24-2001 10:36 PM
normally when we run script with filename
another shell will fork and when it finish , it will return back to current shell and all exported variable was gone.
09-24-2001 10:42 PM
The variables that are exported as part of the
script run as a completely seperate process
and are not part of your shell environment, so
when the script completes, the variables
that are associated with script complete also.
If you want to add them to your own env, add
them to either your own .profile or .login or
the file associated with the sheel you are using.
09-24-2001 10:50 PM
There are two types of variable in HPUX. One is environment variable and other is shell variable. Shell variables are applicable only to that shell. Not visible to parents.
If U are executing a script in a new shell, the all variable set in that script will be applicable only to that new shell. Once U come out of the script, that shell will get closed. Means ur variables also disappears.
Whenever U are executing a script from the parent shell (like ./script), U are not creating a new shell. the changes will reflect here and it will make changes in environment variables.
Best of luck
09-25-2001 01:02 AM
thanks for yr helps.but i still has a little annoy about it.
when i want to set some Env variavles,then
i has to modify the .profile only?
because when i use Weblogic, there is always a file "setEnv.sh",so i has to run it using ". setEnv.sh"??
09-25-2001 01:29 AM
If you need to have this set all the time, then yes, you'd have this statement in your ~/.profile so that it gets sourced every time you log in.
The reason that these settings don't stay when you execute the script is that when you execute the script, it spawns a subshell, sets up everything in the subshell and then exits the subshell effectively leaving you where you started, i.e. without the setting.