in reply to any efficient way to get user's full name?
This saves in $user_name whatever is in the comment field of the user's entry in the password file (assuming comments are in the sixth field).$user_name = (getpwuid($<))[5];
Update: Due to the way different systems handle the comments field, the above may not work on all systems. I tested the above on Solaris 2.6 and it worked. mdillon alerted me that the name is available from the GCOS field on his system which means the index 6 should be used.
When I looked again on the Solaris system, I found that the name was available in both comment and GCOS fields. On my Linux (Debian) box it is in the GCOS field.
So, it seems that using index 6 seems to be working on both Solaris and Debian Linux systems. Here's the updated code:
Thanks to mdillon for the correction.$user_name = (getpwuid($<))[6];
PS: Does anyone know the story behind the GCOS field? What does it stand for? Why do both comment and GCOS fields both exist?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: any efficient way to get user's full name?
by ChemBoy (Priest) on Jul 26, 2001 at 02:27 UTC | |
by grinder (Bishop) on Jul 26, 2001 at 12:54 UTC | |
|
The story behind GECOS
by grinder (Bishop) on Jul 26, 2001 at 12:50 UTC |