Defindit Docs and Howto Home

This page last modified: Nov 09 2004
/usr/bin/logname: no login name

The builtin Perl function getlogin() and /usr/bin/logname fail in
Fedora Core 2 (Linux, and maybe many Unix-like systems).
It breaks if stdin is changed, i.e. you redirect stdin.

touch tmp.txt
try.pl < tmp.txt

You can also break it by running try.pl from inside Emacs. I used the
compile window and compiled:

perl try.pl



#!/usr/bin/perl

$temp = `/usr/bin/logname`;

if (! $temp) 
{
    $temp = "\n";
}

print "Results of logname:$temp";

$temp = getlogin();

print "Results of getlogin:$temp\n";

$temp = `/usr/bin/whoami`;

print "Results of whoami:$temp";

print "LOGNAME: $ENV{LOGNAME}\n";