jeremyw has asked for the wisdom of the Perl Monks concerning the following question:
I'm trying to figure out how to grab the username or login id on a unix/linux os. I figured out how to grab the username on a windows os (see the code below):
# Grab username from PC: my $author= "$^O user"; if ($^O =~ /mswin/i) { $author= $ENV{USERNAME} if defined $ENV{USERNAME}; } else { $author = "$first $mid $last"; }
I use the variable $author to print the username in a new file for documentation purposes. My perl script will be used on both Windows and Unix/Linux operating systems, so I'd like to include the ability to determine either. Any help is greatly appreciated.
Thanks,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How do you grab username/login id in Unix?
by Corion (Patriarch) on Dec 02, 2004 at 08:47 UTC | |
|
Re: How do you grab username/login id in Unix?
by gaal (Parson) on Dec 02, 2004 at 04:58 UTC | |
|
Re: How do you grab username/login id in Unix?
by pearlie (Sexton) on Dec 02, 2004 at 05:17 UTC | |
|
Re: How do you grab username/login id in Unix?
by htoug (Deacon) on Dec 02, 2004 at 07:04 UTC | |
by Luca Benini (Scribe) on Dec 02, 2004 at 07:22 UTC | |
|
Re: How do you grab username/login id in Unix?
by Anonymous Monk on Dec 02, 2004 at 10:36 UTC | |
by jeremyw (Novice) on Dec 02, 2004 at 17:46 UTC |