Operating System - HP-UX
1753814 Members
8224 Online
108805 Solutions
New Discussion юеВ

Environment variable of one particular user when root !

 
Leo The Cat
Regular Advisor

Environment variable of one particular user when root !

Hi again (sorry)

I'm root and I need to get the value of a particular environment variable for my user test.

A complex way is to retrieve it by the command below:
grep -i MYVAR /home/test/.profile

and use some substring extraction !


Is there another way ?

Regards
Den
2 REPLIES 2
Pete Randall
Outstanding Contributor

Re: Environment variable of one particular user when root !

As root you can become the user with the su command and then test for the variable:

su - username (note the space between the - and username - this causes the user's environment to be set up by login)
env |grep -i MYVAR

This accomplishes the same thing but is probably a more thorough test then just checking .profile. MYVAR could be set somewhere else other than just .profile.


Pete

Pete
Steven Schweda
Honored Contributor

Re: Environment variable of one particular user when root !

> Is there another way ?

Depending on exactly what you mean, I know of
no good way. Looking at a user's shell
start-up script may tell you what the value
of one of his environment variables is, but
what stops him from changing it manually?
And how will looking at his ".profile" tell
you what he's typed?

Why "-i" with grep? Aren't shell variables
case-sensitive?

Is there some actual problem which you are
trying to solve?