1833083 Members
4188 Online
110050 Solutions
New Discussion

How do I set ENVIROMENT

 
Narendran.S
Occasional Contributor

How do I set ENVIROMENT

How do I actually set enviroment in HPUX_11 under csh or ksh.
What do I need to do so that the enviroment will allways be in the PATH. Do I need to make an entry in some files.

Thanks & Regards

Naren.S
Viva HPUX
8 REPLIES 8
harry d brown jr
Honored Contributor

Re: How do I set ENVIROMENT

You can add the PATH to /etc/profile or to the users home directory .profile, and with ksh in .kshrc in their home directory.

live free or die
harry
Live Free or Die
A. Clay Stephenson
Acclaimed Contributor

Re: How do I set ENVIROMENT

You can set it in /etc/profile to do this on a global basis:
e.g.
MYVAR=xxx
export MYVAR

You then can set it the same way in the user's
.profile in his home directory (ksh,sh) or in
.cshrc if using csh.

Note that the .profile entries occur after the /etc/profile settings, so that the .profile can override the /etc/profile values. However, any user can then simply do
a MYVAR=yyy; export MYVAR and that MYVAR is then changed for that process and any of its children regardless of the original value.

If it ain't broke, I can fix that.
Helen French
Honored Contributor

Re: How do I set ENVIROMENT

Hi Narendran,

Like 'sh', ksh using /etc/profile as the global profile and $HOME/.profile as the user specific profile.

In csh, /etc/csh.login is the global profile and $HOME/.login is the user specific profile.

For making any changes to the environmental variables ( permanently) you can edit these files.

HTH,
Shiju
Life is a promise, fulfill it!
oiram
Regular Advisor

Re: How do I set ENVIROMENT

Hi,

If you want some directories be included in the PATH variable you should add them in the file /etc/PATH. See /etc/MANPATH too.

Best regards,
Mario.
Peter Kloetgen
Esteemed Contributor

Re: How do I set ENVIROMENT

Hi,

it depends on how your systems are configured:

/etc/profile is read for each user who logs onto the system. So put things like variables here to be sure everyone has them.

.cshrc is read everytime, you open a c-shell if this file exists in your home- directory.

.login is read, if you use a c- shell as login-shell and if the file exists in your home- directory when you login.

.kshrc is read every time, when you open a korn- shell and if this file exists in your home- directory.

.profile is read every time, when you login, and don't use CDE, or when logging in and if you commented out the line

DTSOURCEPROFILE=true

in your .dtprofile in home- directory and if you use korn- bourne- or POSIX- shell. So you have to take care that these files exist and are configured properly. ( have a look into /etc/skel to find out if the needed files are there.... )

The only thing you have to do now is to find out which of these files you need and to put the variables into them. Take care, c- shells use a different syntax to assign values to variables:

setenv var = value
export var
All other shells use:

export var=value

only bourne shell can't do this, you have to use two commands here:

var=value; export var

Allways stay on the bright side of life!

Peter
I'm learning here as well as helping
Ralph Grothe
Honored Contributor

Re: How do I set ENVIROMENT

Hi Narendran,

what do you mean by:
"What do I need to do so that the enviroment will allways be in the PATH"?

Do you simply wish to define PATH depending on the shell used?

You should consult the manpages of the various shells.
In each, near the bottom you will find a FILES section which lists all files relevant to the shell.

As a general rule of thumb, here I have to correct Peter, one can say that all login shells from the *Bourne* shell family (e.g. sh, ksh, bash) first source /etc/profile.
This is the file where root places environment definitions valid for all Bourne-compatible login shells.

The shells from the C-Shell family (e.g. csh, tcsh) instead have /etc/csh.login as
such a file.

In HP-UX's /etc/profile you will notice a statement similar to

PATH=`cat /etc/PATH`

which dumps the contents of HP-UX's special file /etc/PATH in the global PATH environment variable.
So on HP-UX root should set the general PATH for every account with a login shell rather in /etc/PATH.
The same goes for the env var MANPATH.

Besides, every user is free to (re)define ones own environment settings in their home directory by placing commands in .profile (sh, ksh, bash), .bash_profile (bash), .login (csh, tcsh).

However, the settings therein only become effective for login shells.

If you wish to have your settings in every shell you may define an environment variable ENV which is set to another commands file in your $HOME (this holds for ksh, and HP-UX's posix-sh).
Usually one would take .shrc (or .kshrc, .bashrc) as a filename for that.

The c-shells (and bash) have additionally a .logout file for commands to be executed right before logout (e.g. some clean up stuff)
You can mimic this in HP-UX's posix-sh by trapping SIGEXIT or 0 in your .profile
e.g.
trap 'echo by $LOGNAME' 0

If you have other files where you make certain settings, you can always source them, so that (re)definitions become valid in your current shell.
Use either the . (Bourne shells), or the source command (C-shells, Bash).

Setting of environment variables is as simple as setting any normal shell variable, but additionally you have to export it

MY_VAR=BlaBla
export MY_VAR

for the Bourne shells

setenv MY_VAR = BlaBla

for the C-shells
Madness, thy name is system administration
Bill Hassell
Honored Contributor

Re: How do I set ENVIROMENT

ARe you using a workstation and using CDE? The dtterm/hpterm/xterm windows bypass all classic Unix profiles. To fix this, you need to set the Xwindow environment variable: loginShell to true. The easiest is to do this:

echo '*loginShell: true' >> $HOME/.Xdefaults

Then logout and log back into CDE. Now, terminal windows will behave like 'mormal' Unix.


Bill Hassell, sysadmin