Should "su" change the USER environment variable?

mrose.uci-750a%rand-relay at sri-unix.UUCP mrose.uci-750a%rand-relay at sri-unix.UUCP
Tue Oct 25 13:19:35 AEST 1983


From:  Marshall Rose <mrose.uci-750a at rand-relay>

    Well, (it's my opinion that) $USER is a convenient method to
    determine who you want to say you logged in as.  Under 4.1a, for
    example, if you use a /dev/ptyxx to give a process its own
    control-terminal, it doesn't have an entry in /etc/utmp. Hence,
    things like getlogin() may not work as expected.  In cases like
    this, $USER is real useful as a pointer to who you logged in as.
    Granted, you can easily change it, so it's not a guaranteed method.

    It also seems to me that when something runs under cron, it doesn't
    have a $USER.  This makes it real easy for a script (e.g., .cshrc)
    to tell when it's running under the restricted cron environment.
    For example, I have several maintenance logins that I and others
    use quite heavily.  We each have our own preferred aliases, etc.,
    etc., so we each would want to have a copy of our own .cshrc in
    place for these logins.  Instead, we use this, which does the
    obvious things and we all live in pseudo-harmony.

printenv USER >& /dev/null
if ($status != 0) then
    set path=(/bin /usr/ucb /usr/bin /usr/uci .)
    goto crontab
endif

if (-r ~/.$USER) then
    source ~/.$USER
else
    if (~$USER/.cshrc != ~/.cshrc) source ~$USER/.cshrc
endif

umask 0022
crontab:


    Granted, there are lots of ways of doing this, but it works well
    for our purposes.

/mtr



More information about the Comp.unix.wizards mailing list