Operating System - HP-UX
1828225 Members
2403 Online
109975 Solutions
New Discussion

Setting environment variables

 
SOLVED
Go to solution
Pete Mattison
Advisor

Setting environment variables

I would like to set environment variables that don't disappear just because I have closed and reopened a terminal window, but how? The book's instructions don't help. Also, is it possible to set an environment variable on one terminal window and see the changes on another one?

As an example, I have perl in /opt/perl5 and would like to make this available from everywhere...

Thank you,

Pete
5 REPLIES 5
Bill McNAMARA_1
Honored Contributor

Re: Setting environment variables

set them up in your .profile via the
export VALUE=whatever

#echo $VALUE
whatever

(setenv in csh)

this will ensure that your shell will set them up even if you fork other shells.

Later,
Bill
It works for me (tm)
Rob Smith
Respected Contributor
Solution

Re: Setting environment variables

Hi, make sure you export all the variables you want your child shells to inherit. Example - Set Up Shell Variables:
EDITOR=vi
LANG=c
HISTSIZE=201
HISTFILE=$HOME/.sh_history
ORGANIZATION="Genzyme Biosurgery"
LPDEST=RRA106
export EDITOR LANG HISTSIZE HISTFILE ORGANIZATION LPDEST

Now any window you open will have these variables set. Hope this helps.

Rob



Learn the rules so you can break them properly.
A. Clay Stephenson
Acclaimed Contributor

Re: Setting environment variables

First you have to realize a few things about environment variables. The export goes only one way from parent to child. If you set a var e.g. MYVAR=xxx in a process and export MYVAR
you will see the value xxx in the parent and all child shells or processes. However, if you
set MYVAR=yyy in a child process and export it, the parent will still see the value 'xxx'.
If you really need bidirectional setting of
values you will need to use files or pipes.
For simple things like PATH, you can use the .profile's for each user or if it truly global set a value in /etc/profile. /etc/profile can be used to set a variable and export it to everyone. You can also define global PATH's and MANPATH's by setting them in /etc/PATH and /etc/MANPATH.
If it ain't broke, I can fix that.
James Martens
Occasional Contributor

Re: Setting environment variables

Good morning, Pete.

There's a few global environment files that are available in /etc which you can use to set an environment globally for all users (at least, from what I can see in HP/UX 11.00...):

/etc/PATH : Set global PATH parameter
/etc/MANPATH : Set global MANPATH parameter
/etc/SHLIB_PATH : Set global shared library PATH
/etc/profile : Generic system-wide profile. Normally kept to the bare minimum of what every user needs. /etc/profile normally sources /etc/PATH and /etc/MANPATH.

Follow the same steps (for exporting the variable) that Bill shows above. In /etc/profile, this is for /usr/bin/sh initialization, so no C shell here!



Joseph C. Denman
Honored Contributor

Re: Setting environment variables

Above statements are good, but one more thing to remember consider.

If you modify the .profile and are using CDE, you need to make sure the DTSOURCEPROFILE=TRUE in the .dtprofile. This cause the .profile to be read when you open a terminal.

...jcd...
If I had only read the instructions first??