in reply to Re: any efficient way to get user's full name?
in thread any efficient way to get user's full name?

Or, alternatively,

$username = (getpwnam(getlogin))[5];
which is probably infinitesimally slower and infinitesimally more self-documenting. But I happen to have used that particular idiom, so I thought I'd throw it in. :-)

Update: in the spirit of actually adding something to the discussion, I should point out that there is an entire class of built-in functions to deal with users and groups, named things like getpwnam, getgrent, getgrgid and the like, which you should look at if you ever so much as think of directly accessing /etc/passwd directly (you can find the complete list under "Fetching user and group info" here).

Update 2: fields 5 and 6 are identical here, too (SGI), FWIW. And I hadn't considered su, but it seems like that will cause issues not matter what you do, yes?



If God had meant us to fly, he would *never* have give us the railroads.
    --Michael Flanders

Replies are listed 'Best First'.
Re:x3 any efficient way to get user's full name?
by grinder (Bishop) on Jul 26, 2001 at 12:54 UTC
    Danger Will Robinson!

    This code will fail if the user has employed su(1) to change who they are on the system. If you su to root and run this code, you retrieve the original name. Which may or may not be what you wanted...

    --
    g r i n d e r