Finding the user name via the shell

Jim O'Connor jim at fsc2086.FSC.COM
Sat Dec 10 03:13:48 AEST 1988


In article <484 at fallst.UUCP>, tkevans at fallst.UUCP (Tim Evans) writes:
> In article <249 at tfli.UUCP>, mikej at tfli.UUCP (Michael R.  Johnston) writes:
> > 
> > The correct answer is to use the variable $LOGNAME.
> 
> Although the $LOGNAME variable is supported generally on System V *NIX, SCO
> Xenix 2.2 does _not_ support it.  Rather, as I and others have noted here
> previously, the Xenix _command_ 'logname' (note lowercase) returns the 
> user's login name.

Actually, it's just that Xenix 2.2 doesn't set it automatically at login
time.

If you are used to having the $LOGNAME variable present (such as I was when
switching from Altos Xenix to SCO Xenix) and your "login" program won't set
it for you, just add:

LOGNAME=`logname`     # or any program that will return the user's log name
export LOGNAME

to your /etc/profile file or your user's individual profiles and then $LOGNAME
will be available.  This is also handy for other "constants" that usually
require running some program to get the value of.  For example, 

LOCALSYS=`uuname -l`
PORT=`tty`
...
export LOCALSYS PORT . . .

Then, if you write many shell scripts that require these values, you can look 
them up in the environment and save a little fork() and exec() time (same
argument as for shell built-in commands).  But, if you don't use these
values much, you'd probably be better off just running hte program in the
scripts themselves, and save the extra time it would take to process
everyone's login sequence.  It's the old "6 of one, half-dozen of the other"
type thing, and you just have to decide for yourself which one is better.

If you are writing scripts to port to other machines, however, you should
probably use the program in the script, since you wouldn't want to assume
other systems will use the pre-set variables.

--jim
------------- 
James B. O'Connor				jim at FSC.COM
Filtration Sciences Corp.			+1 615 821 4022 x651
105 W. 45th St. - Chattanooga, TN 37409



More information about the Comp.unix.xenix mailing list