Languages and Scripting
Showing results for 
Search instead for 
Did you mean: 

A strange thing in HP-UX

Occasional Contributor

A strange thing in HP-UX

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

I am a worm of software development.
Esteemed Contributor

Re: A strange thing in HP-UX

. filename = execute in this shell , don't fork new shell

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.
enjoy any little thing in my life
Michael Tully
Honored Contributor

Re: A strange thing in HP-UX


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.

Anyone for a Mutiny ?
Esteemed Contributor

Re: A strange thing in HP-UX


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
Occasional Contributor

Re: A strange thing in HP-UX

hello :
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 "",so i has to run it using "."??
I am a worm of software development.
Santosh Nair_1
Honored Contributor

Re: A strange thing in HP-UX

What you'd want to do is to source the Weblogic environment variables. You'd do this by executing:

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.

Life is what's happening while you're busy making other plans