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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Silly question: How to obtain UID w/in C shell? 1

Status
Not open for further replies.

goldenradium2001

Technical User
Mar 22, 2002
91
0
0
US
Hi there,

I did this to try to obtain the current UID from bash:

# echo $UID

How do I obtain the current UID from the C shell? It reads that it cannot recognize the variable. I tried to echo $uid as well. I echoed $USER but I got the user's name not the UID. I want to use the UID.

I executed the id command but I got the UID and a bunch of other stuff.

Help? I just want the UID. Thanks.
 

id |sed -e 's/).*//' -e 's/.*(//' -----------
when they don't ask you anymore, where they are come from, and they don't tell you anymore, where they go ... you'r getting older !
 
Hi:

One of these 4 should work:

1)
id|sed -e 's,^[^(]*(,,' -e 's,).*$,,' -e 1q

2)
id|sed 's/^uid=[0-9]*(\(.*\)) gid.*/\1/'

3)
who am i | cut -d" " -f1

4)
id|awk ' {
start=index($0, "(")
endit=index($0, ")")
print substr($0, start+1, endit-start-1)
} '
 
Hi all, actually I was aiming to get the numerical UID. I modified jamisar's sed syntax to get it. Here's what I used:

id | sed -e '/(.*//' -e 's/uid=//'

This got me the numerical UID.

Thanks for everyone's help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top