This turns out to duplicate getent
, which is already available on Solaris and Linux. The standard getent
should be used instead of getpw
for all purposes.
The getpw
command is a command-line interface to the getpwnam
, getpwuid
, and getpwent
system calls.
It takes a single parameter, which may be a userid, a user number (uid), or ":". If a userid or uid is supplied, the matching entry is retrieved using getpwnam
or getpwuid
respectively and printed out in password file format. If the parameter is ":" then getpwent
and associated calls are used to iterate through the entire set of users and the whole list is printed out.
If the userid or uid does not exist, the message "No such user!" is displayed and the program exits with status -2.
The intent of this is to replace cat /etc/passwd
and similar formulations with something that should work even if there is no actual password file on the machine. The output of getpw :
should be identical to the contents of the password file.
To display the password entry for user jnsmith
:
getpw jnsmith
To display the password entry for the user with uid 105:
getpw 105
To display the password file:
getpw :
The error message is displayed on stdout, not stderr where it belongs.
-- IsaacMorland - 10 Jan 2007