[comp.unix.xenix.sco] LOGNAME, USER variables under Xenix

tran@peora.sdc.ccur.com (Nhan Tran) (04/26/91)

  When I log in Xenix, running /bin/sh, the environment variable LOGNAME
and USER are not set.  And Xenix doesn't have whoami command.  Is there
any quick way to to get users login id other than id command (which you
have to parse it to get the login id)

Nhan Tran

slootman@dri.nl (Paul Slootman) (04/26/91)

In article <4731@peora.sdc.ccur.com> tran@peora.sdc.ccur.com (Nhan Tran) writes:
>
>  When I log in Xenix, running /bin/sh, the environment variable LOGNAME
>and USER are not set.  And Xenix doesn't have whoami command.  Is there
>any quick way to to get users login id other than id command (which you
>have to parse it to get the login id)

Use the command "logname"; that works for me. Xenix also recognizes the
command "who am i" (note the spaces). However, this also gives you the
tty line and login time.

Place this in your .profile:

LOGNAME=${LOGNAME:-`logname`}
USER=${USER:-$LOGNAME}
export LOGNAME USER

This should work. RTFM for sh(1) if you're not clear on what happens
here. Good luck.
-- 
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
: slootman@dri.nl           : You are wise, witty and wonderful, but you      :
: ...!hp4nl!dri500!slootman : spend too much time reading this sort of trash. :
 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

tran@peora.sdc.ccur.com (Nhan Tran) (04/27/91)

   Thanks to all who answer my little question about LOGNAME !

Nhan Tran

bill@bilver.uucp (Bill Vermillion) (04/27/91)

In article <4731@peora.sdc.ccur.com> tran@peora.sdc.ccur.com (Nhan Tran) writes:
 
>  When I log in Xenix, running /bin/sh, the environment variable LOGNAME
>and USER are not set.  And Xenix doesn't have whoami command.

Xenix does have a whoami command, except is typed   who am i   three
words.


-- 
Bill Vermillion - UUCP: uunet!tarpit!bilver!bill
                      : bill@bilver.UUCP

mju@mudos.ann-arbor.mi.us (Marc Unangst) (04/30/91)

bill@bilver.uucp (Bill Vermillion) writes:
> Xenix does have a whoami command, except is typed   who am i   three
> words.

Bzzt.  "who am i" (and the variant, "who am I") is not the same as
"whoami", as about 10 seconds of work with a BSD system will tell
you.  "who am i" basically does a "who" and then greps out the line
with your tty name in it.  "whoami" gives the login id that
corresponds to the current UID.

One important diffence is that "who am i" always returns the name in
/etc/utmp, but "whoami" looks at the current UID and generates the
name from that.  This means that "whoami" works as expected when
you're su(1)ed to another user, while "who am i" does not.

--
Marc Unangst               |
mju@mudos.ann-arbor.mi.us  | "Bus error: passengers dumped"
...!hela!mudos!mju         | 

cliffb@cjbsys.bdb.com (cliff bedore) (05/01/91)

In article <1991Apr26.231504.9581@bilver.uucp> bill@bilver.uucp (Bill Vermillion) writes:
>In article <4731@peora.sdc.ccur.com> tran@peora.sdc.ccur.com (Nhan Tran) writes:
> 
>>  When I log in Xenix, running /bin/sh, the environment variable LOGNAME
>>and USER are not set.  And Xenix doesn't have whoami command.
>
>Xenix does have a whoami command, except is typed   who am i   three
>words.
>
>
>-- 
>Bill Vermillion - UUCP: uunet!tarpit!bilver!bill
>                      : bill@bilver.UUCP

The problem is that when you su, who am i gives your login name not root.
There is a whoami program available.  I've included it as a shar file

Cliff



:
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  whoami.c
# Wrapped by schenk@cpsc.UCalgary.CA on Thu Jan  3 23:11:35 1991
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'whoami.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'whoami.c'\"
else
echo shar: Extracting \"'whoami.c'\" \(1326 characters\)
sed "s/^X//" >'whoami.c' <<'END_OF_FILE'
X/*
X * Copyright (c) 1988 Regents of the University of California.
X * All rights reserved.
X *
X * Redistribution and use in source and binary forms are permitted
X * provided that the above copyright notice and this paragraph are
X * duplicated in all such forms and that any documentation,
X * advertising materials, and other materials related to such
X * distribution and use acknowledge that the software was developed
X * by the University of California, Berkeley.  The name of the
X * University may not be used to endorse or promote products derived
X * from this software without specific prior written permission.
X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X */
X
X#ifndef lint
Xchar copyright[] =
X"@(#) Copyright (c) 1988 Regents of the University of California.\n\
X All rights reserved.\n";
X#endif /* not lint */
X
X#ifndef lint
Xstatic char sccsid[] = "@(#)whoami.c	5.3 (Berkeley) 6/29/88";
X#endif /* not lint */
X
X#include <sys/types.h>
X#include <pwd.h>
X
Xmain()
X{
X	struct passwd *p, *getpwuid();
X	int uid;
X
X	uid = geteuid();
X	if (!(p = getpwuid(uid))) {
X		printf("whoami: no login associated with uid %u.\n", uid);
X		exit(1);
X	}
X	printf("%s\n", p->pw_name);
X	exit(0);
X}
END_OF_FILE
if test 1326 -ne `wc -c <'whoami.c'`; then
    echo shar: \"'whoami.c'\" unpacked with wrong size!
fi
# end of 'whoami.c'
fi
echo shar: End of shell archive.
exit 0
-------------------------------------------------------------------------------
Eric Schenk               Department of Computer Science, University of Calgary
schenk@cpsc.ucalgary.ca   Just another graduate slave.
-------------------------------------------------------------------------------