[comp.unix.questions] One way to fix $LOGNAME after `su - foo`.

tony@oha.UUCP (Tony Olekshy) (07/21/90)

The recent discussion on the difference between uid and $LOGNAME was prompted
by (or at least included discussion of) the fact that on SCO Xenix (and Unix,
I believe) the value of $LOGNAME after `su - foo` is the same as before the
su, when in fact it should be "foo".

I have solved this problem under SCO Xenix by adding the following incantation
to the /etc/cshrc file:

    setenv LOGNAME	"`id | sed 's/[^(]*(\([^(]*\)).*/\1/'`"

Please note that, under SCO Xenix, /etc/cshrc is only sourced at login time
*and* by the `su - foo` command.  Under other models of Unix or other shells,
you may need to find some other condition that is only true at login and
`su - foo` times, and use that to trigger LOGNAME resetting.  You might try
$0 or `env`.

As a result, by the way, the `setenv MAIL "/usr/spool/mail/$LOGNAME"` that
is embedded in my /etc/cshrc now works that way I thought it should: if I
`su foo` I am still notified of changes to my mailbox, and if I `su - foo`
I am notified of changes to foo's mailbox.

--
Yours etc., Tony Olekshy.               Internet: tony%oha@CS.UAlberta.CA
					  BITNET: tony%oha.uucp@UALTAMTS.BITNET
					    uucp: alberta!oha!tony