http://www.perlmonks.org?node_id=411668


in reply to How do you grab username/login id in Unix?

$ENV{LOGNAME} should do it in many cases. It has been defined as the username on all systems I have used.

But the getpwxxx method that gaal showed is probably the best. It should work on more than just unix.

  • Comment on Re: How do you grab username/login id in Unix?

Replies are listed 'Best First'.
about LOGNAME
by Luca Benini (Scribe) on Dec 02, 2004 at 07:22 UTC
    $ENV{LOGNAME} is setted at login time, so if someone log in as popeye and the do
    su
    his $ENV{LOGNAME} is again popeye. But if popoye do
    su -
    his $ENV{LOGNAME} is again popeye.