bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: getpwnam


From: Bruce Korb
Subject: Re: getpwnam
Date: Thu, 01 Jan 2004 13:14:25 -0800

Andreas Schwab wrote:
> 
> Bruce Korb <address@hidden> writes:
> 
> > Hi Andreas,
> >
> > Andreas Schwab wrote:
> >> >>   getent passwd bob
> >> >>   bob:x:1000:1000:Bob Proulx,,,:/home/bob:/bin/bash
> >> >
> >> > 1.  you cannot get it by user id,
> >>
> >> Yes, you can.
> >
> > OK.  I only read the man/info pages.
> 
> getent uses the same interfaces as getpwnam, getpwuid, etc.

So, why doesn't the page tell me how to determine the needed
entry given that my program is a script and really just wants
the full user name of the current user?  Specifically, how can
it be used to simplify the following:

  lname=`id | sed 's/ .*//;s/)//;s/.*(//'`
  fname=`getent passwd $lname | awk -F: '{ print $5 }'`

the main complexities are:
 1. lname may appear as 'uid=1234'
 2. getting lname is a hassle anyway
 3. Remembering that the user name is the fifth field is much harder
    to remember than ``getpwnam -h'' or ``getent passwd me'' and
    count colons
 4. two pipes + two subshells

Ick.

> The output of getent is much easier to parse than both of your examples.
> The first form is ambigous, and in the second form the tag names likely
> change due to i18n.

Neither one is the usual usage:

  $ getpwnam -N
  Bruce Korb

That's really easy to parse.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]