Operating System - HP-UX
1819927 Members
3159 Online
109607 Solutions
New Discussion юеВ

Re: env variables on hpux 11i

 
SOLVED
Go to solution
Shivkumar
Super Advisor

env variables on hpux 11i

To verify env variable we issue command $env. How and which place i need to set this variables permanently ?
21 REPLIES 21
Oviwan
Honored Contributor

Re: env variables on hpux 11i

Hi

to verify:
set or export

to set permanently:
put them in the $HOME/.profile
export var=blah

Regards
DCE
Honored Contributor

Re: env variables on hpux 11i



system wide is done in /etc/profile

add the following line to set the set the default editor to vi

export EDITOR=vi

or the following lines do the same thing

set EDITOR=vi
export EDITOR

Tp set env variable for an individual user, add the lines in their .profile located in their home directory
James R. Ferguson
Acclaimed Contributor
Solution

Re: env variables on hpux 11i

Hi Shiv:

Aside from the standard environmental variables established during 'login' or a 'cron' tab initiation (see the manpages for both...) you have a couple of options.

You can set (and export) variables in your login profile.

You can create a standalone file that is sourced (read) by your login profile *and* any script that needs it.

In either case, you declare and export variables into your enviroment thusly:

# export MYPLACE=/var/tmp
# export MYID=`whoami`

If you put these examples into a file called "$HOME/mystuff" you would 'source' or read it thusly:

. $HOME/mystuff

Note that the operation of sourcing is to write a dot (".") followed by a space, followed by the filename to be read.

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: env variables on hpux 11i

Unless $env has a value then ${env} is a null command and will do nothing. Your question has no meaning unless placed in some sort of context. The "env" command can be used to both get and set the environent for a command. Man env for details. Assuming that you want to set some global environment variables, the typical way is to insert statements in /etc/profile.

export MYVAR1=this
export MYVAR2=that

Variables that are unique to a user are placed in .profile in the user's home directory. The .profile command are sourcec after those in /etc/profile so that it's possible to override those in /etc/profile.
If it ain't broke, I can fix that.
karan_3
Advisor

Re: env variables on hpux 11i

Hi
se you can verify your environment by using "env" command or individual variable by using echo $variable name) for exp-- echo $DISPLAY.

you can set these variable in the $HOME/.profile file.

thanks
karan
Indrajit_1
Valued Contributor

Re: env variables on hpux 11i

Hi;

U need to set Env variable in $HOME/.profile for each and every independent user.

e.g.

#vi /home/user1/.profile

export TERM=vt100
export PATH=$PATH:/usr/bin/ksh
export HISTSIZE=50
save and come out

#. /home/user1/.profile [enter]

Hope this will help u to resolve ur issue

Cheers
Indrajit
Never Ever Give Up
Steven E. Protter
Exalted Contributor

Re: env variables on hpux 11i

Shalom,

Besides the standard environment script, any script can change environment variables.

Just set them like you would on the command line, export them and bingo, environment change.

to run them . scriptname

dot space scriptname.

Many of the applications running on an HP-9000 server require custom environment settings. Many of the Oracle applications you mentioned in your other posts required some environment customization.

So you'll be needing to do a lot of customization work on environments, if your post volume reflects the complexity of your actual servers.

I handle most of these issues when possible in the startup scripts. The users that own the various applications often require .profile or add in environment to properly manage their applications.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
James R. Ferguson
Acclaimed Contributor

Re: env variables on hpux 11i

Hi Shiv:

If you add environmental variables to your user's profile's the temptation will be to source your profile in 'cron' jobs to have the variables passed into the environment.

This will lead to your cron jobs mailing their users messages complaining "not a typewriter". This occurs when terminal-oriented commands like 'stty' and 'tset' run in a terminal-less environment like a cron task.

While there are several ways to circumvent this, isolating your custom, environmental variables in their own file and (1) sourcing this file in your login profile; and (2) sourcing this file in any script that needs the variables; solves the problem.

Regards!

...JRF...
Arunvijai_4
Honored Contributor

Re: env variables on hpux 11i

Hi Shiv,

To set these variables permanently, you can modify these files,

/etc/profile
$HOME/.profile
# export $VARIABLE=New_Value

-Arun

"A ship in the harbor is safe, but that is not what ships are built for"
Arunvijai_4
Honored Contributor

Re: env variables on hpux 11i

Hi Shiv,

Some links about Shell variables which will help you to dig further

http://heather.cs.ucdavis.edu/~matloff/UnixAndC/Unix/ShellIntro.html
http://www.scit.wlv.ac.uk/~jphb/spos/notes/shell/shell1.html

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Senthil Prabu.S_1
Trusted Contributor

Re: env variables on hpux 11i

Hi Shiva,
The files you need to edit are
/etc/profile
$HOME/.profile

Any env command is used to verify the environment variables. Also you must know difference between set and env.

The set command shows all of the variables which have a value in the current shell instance. The env command shows all of the
current environment variables --- those variables which are inherited by (and visible to) newly created children


--
Prabu.S
One man's "magic" is another man's engineering. "Supernatural" is a null word.
Muthukumar_5
Honored Contributor

Re: env variables on hpux 11i

You can do it with /etc/profile or $HOME/.profile file. May in some ather file and include in /etc/profile or $HOME/.profile as,

.

--
Muthu
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: env variables on hpux 11i

For temporary usage,

you can declare variable as,

# export var="test"
# set var1="test"
# var2="test"

like that. Access scope of these will be differing in sub-shell.

--
Muthu
Easy to suggest when don't know about the problem!
Arunvijai_4
Honored Contributor

Re: env variables on hpux 11i

Hi Shiv,

To know more about ENV, take a look at this,

http://docs.hp.com/en/B2355-90046/ch23s02.html?btnNext=next%A0%BB
[Shells: User's Guide > Chapter 23. Advanced Concepts and Commands -->The ENV Variable ]

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Shivkumar
Super Advisor

Re: env variables on hpux 11i

James, could you please elaborate your second reply in great detail ? regards.
Arunvijai_4
Honored Contributor

Re: env variables on hpux 11i

Hi Shiv,

JRF says, when you use custom varaibles in your profile, it will affect "cron" jobs running. To overcome this issue,

Isolating your custom, environmental variables in their own file and (1) sourcing this file in your login profile; and (2) sourcing this file in any script that needs the variables; solves the problem.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
Bharat Katkar
Honored Contributor

Re: env variables on hpux 11i

Shiv,
For e.g. if you would like to export two variable xyz and abc as follows:

# export XYZ=value1
# export ABC=value=2

Now instead of doing this directly into users profile we source the file which contains these variables. Like:

# vi file1
Add:
export XYZ=value1
export ABC=value=2
Save file:

Then you can do it as:

# source file1

Or add "source file1" into users profile.

This way you isolate these two variables from other environmental variables.

Hope that helps.
Regards,

You need to know a lot to actually know how little you know
Arturo Galbiati
Esteemed Contributor

Re: env variables on hpux 11i

Hi SHiv,
waht James writed in that you set some variabiles about terminal setting if you run your .profile inc rontab (no tty attached) you will receive an error.

To avoid this you can use:
if [[ $(tty) != "not a tty" ]] # tty attached
then
export bold=$(tput bold)
fi


HTH,
Art
Raj D.
Honored Contributor

Re: env variables on hpux 11i

Shiv,

good day!

Also you can go through the manpage , when you get a chance :

# man sh-posix
Hope that will help to understand the environment variables.



Best Regards,
Raj.
" If u think u can , If u think u cannot , - You are always Right . "
James R. Ferguson
Acclaimed Contributor

Re: env variables on hpux 11i

Hi (again) Shiv:

You asked me to elaborate on my remarks about not adding environmental variables to login profiles.

First, understand that I am stating a *preference* of technique; *not dogma*.

The HP-UX Posix shell profile ('.profile') attempts to discern the characteristics of a terminal during login when the profile is processed. Part of the processing involves 'tset' and 'stty' commands. These functions expect STDIN to be associated with a terminal. If it isn't, as would be the case if you read your profile in a cron'ed script, then the message "Not a typewriter" is generated to STDERR.

Remember that any cron task that doesn't redirect STDOUT or STDERR will have that output mailed to the initiating user.

Now, consider what happens if you setup a cron task but source (read) your profile to gain your environmental variables for running it:

# . ./profile; ./somescript

[ The Forum may close-up the spaces above. That's a dot, a space, and then ".profile" ]

You propagated your environmental variables to your script just as you wanted, but you also got mail announcing "Not a typewriter" when your script ran.

There are several ways to eliminate this problem.

The first way around this annoyance is to redirect STDERR to /dev/null:

# . ./profile 2> /dev/null; ./somescript

There are two other solutions, too.

The first, is to modify your login profile to only execute its terminal-oriented commands when the process enviroment *is* terminal-based. Then, you are free to add environmental variables and source the profile as we first did.

To query the environment use [ -t 0 ] tests like:

if [ -t 0 ]; then
echo "I am terminal-based"
else
echo "I an NOT associated with a terminal"
fi

This ascertains whether STDIN (file descriptor 0) is associated with a terminal.

While I generally amend my login profiles with the [ -t 0 ] logic, I prefer to source a separate file of environmental variables. If I want these set during login, I source the file from the login profile. Otherwise, if I only need the variables in individual scripts, I source them within those scripts.

This is merely my preference, not dogma as I first stated. This is consistent with the Unix philosophy that there's more than one way to do anything!

Regards!

...JRF...
Shivkumar
Super Advisor

Re: env variables on hpux 11i

James, I always respect your and others opinions. This forum is giving me confidence to take next assignment as sys admin of hpux. Warm Regards. Shiv