Retrieving unique user numbers
Hans Mulder
hansm at cs.kun.nl
Sat Apr 27 00:23:58 AEST 1991
In <1991Apr25.153217.9572 at oakhill.sps.mot.com> root at oakhill.sps.mot.com (Operator) writes:
>Hello all --
>I was asked by a user how to retrieve/identify the unique
>user number from within the shell environment (ksh). What
>he is looking for would, preferably, function in much the
>same fashion as the command [echo `/usr/bin/logname`], where
>the result of this op could then be piped into a subsequent
>operation.
On this system (running SunOS 4.1.1)
id | sed 's/[^=]*=//;s/(.*//'
tells you your uid. You didn't say what OS you are running.
The man page for id(1v) suggest that it is a SysVism, so it may not be
available on your system.
If you're worried about the efficiency of invoking sed, you'll have to
write a C program that prints the output of the getuid() system call.
BTW, is there any difference between
echo `/usr/bin/logname`
and
logname
?? In general, the echo `...` constructs reduces whitespace, but your
users don't have whitespace in their login names, have they?
>Many thanks,
You're welcome
>Vance
Hans Mulder hansm at cs.kun.nl
More information about the Comp.unix.shell
mailing list