Re: A strange thing in HP-UX (181 Views)
Reply
Occasional Contributor
huomzh
Posts: 5
Registered: ‎09-24-2001
Message 1 of 6 (181 Views)

A strange thing in HP-UX

[ Edited ]

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
Printaporn_1
Posts: 609
Registered: ‎02-06-2001
Message 2 of 6 (181 Views)

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
Honored Contributor
Michael Tully
Posts: 7,905
Registered: ‎04-15-1999
Message 3 of 6 (181 Views)

Re: A strange thing in HP-UX

Hi,

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.

HTH
-Michael
Anyone for a Mutiny ?
Esteemed Contributor
Shahul
Posts: 656
Registered: ‎02-25-2001
Message 4 of 6 (181 Views)

Re: A strange thing in HP-UX

Hi

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
Shahul
Occasional Contributor
huomzh
Posts: 5
Registered: ‎09-24-2001
Message 5 of 6 (181 Views)

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 "setEnv.sh",so i has to run it using ". setEnv.sh"??
huomzh
I am a worm of software development.
Honored Contributor
Santosh Nair_1
Posts: 1,020
Registered: ‎07-18-2000
Message 6 of 6 (181 Views)

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:

. setEnv.sh
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.

-Santosh
Life is what's happening while you're busy making other plans
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.