Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Current User 2

Status
Not open for further replies.

Michael42

Programmer
Oct 8, 2001
1,454
US
Hello,

On a Solaris 8 and 10 systems in a Bourne shell script I need to set the current user to a variable. My problem is I cannot use an environment variable like LOGNAME or USER.

I think maybe I could use id command if I can just extract the username and set it to a variable.

What can you suggest?

Thanks,

Michael42
 
Something like this?
Code:
USERID=`id|sed 's/).*$//g;s/^.*(//g'`
 
SamBones,

Thanks very much sir - that was perfect. :)

-Michael42
 
I guess you could also...
Code:
USERID=`/usr/ucb/whoami`
This is a little easier to understand and does the same thing.
 
There's always more than one way of doing something:

Code:
user=$(id | cut -d\( -f2 | cut -d\) -f1)
 
No logname command in solaris ?
username=`logname`

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Yes, Solaris does have logname. Sometimes we miss the obvious! [bigsmile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top