Environment Variables

Hi Experts,

Need your help in understanding the commands to setup the environment variables in hp-ux.

Beleive need to use either set,setenv or export.

I am confused between above three options, when to use which option?

On command line, I have tried both set and setenv but couldn't able to set the environment variables. However with export it was working fine.

set is used to display the contents of your environment. Issue it and you will get a list of variable=value lines. There are several special variables among these, but it will show you all variables defined in this shell so far.

export is used on variables to have them inherited by processes spawned from this environment.

To explain this in a little more detail: you can start any program from within the shell - even another invokation of this shell. When you declare a variable within a certain shell environment then the program(s) started from this environment does not know about this variable automatically. If the variable is "export"ed it will be known, though.

try the following for yourself:

# ksh
# x="huhu"
# echo $x
huhu
# ksh               # we start a new environment here
# echo $x           # variable x has no value here, because it was not exported
# exit              # leave the new environment
# echo $x           # we are back in the first one
huhu
# export x
# ksh                # again starting a new environment
# echo $x
huhu
# exit

I hope this helps.

bakunin