Operating System - HP-UX
1833059 Members
2662 Online
110049 Solutions
New Discussion

Embarrassingly simple env variable question

 
SOLVED
Go to solution
Doug_3
Frequent Advisor

Embarrassingly simple env variable question

I am a little embarrassed to post this...but here goes

I have a script to change env variables but it is not working. I believe it is set up identical to my .profiles, yet a check of the variable using echo indicates they are not changed.

TESTSETTINGS=defaultconfig.test
export TESTSETTINGS

SERVERNAME=HP9K_serv01
export SERVERNAME

echo $ yields the original .profile settings.

tia
Doug
3 REPLIES 3
Jeff Schussele
Honored Contributor

Re: Embarrassingly simple env variable question

Hi Doug,

The env vars you set in the script are only available to the script or any children it spawns. They cannot be easily passed back to the parent - the shell that runs the script in your case.
Try echoing them inside the script to see their true value while in the script.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Sanjay_6
Honored Contributor

Re: Embarrassingly simple env variable question

Hi Doug,

If you calling another file from your .profile, use this syntax,

. /path_to_file/file_name

Then do a check for the env variable,

echo $SERVERNAME

Hope this helps.

Regds
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Embarrassingly simple env variable question

Hi Doug:

Let me see if this is what you are doing.
Originally in your .profile
XXX=000
YYY=111
export XXX YYY
You created a script, env.sh that does this
XXX=888
YYY=999
export XXX YYY

You then
env.sh
echo $XXX
and you see "000" rather than the expected "888".

------------------------------------------

There is nothing wrong with your code but you are trying to change the parent's env from a child; that dog won't hunt.

What you can do is SOURCE env.sh.
. env.sh

The '.' remains in the foreground and is part of the current shell. You must make certain that your sourced script does not contain an exit or return or you will of cource exit your current (foreground) process.

Regards, Clay
If it ain't broke, I can fix that.