Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: LOGNAME not properly set on FreeBSD



On 2014-04-01 at 16:22 -0500, Erik Johnson wrote:
> When using "su - username" to change users, zsh is not properly setting
> the LOGNAME environment variable on FreeBSD. Example below.

----------------------------8< cut here >8------------------------------
 LOGNAME
    If the corresponding variable is not set in the  environment  of
    the  shell, it is initialized to the login name corresponding to
    the current login session. This parameter is exported by default
    but this can be disabled using the typeset builtin.
----------------------------8< cut here >8------------------------------

This is the _login_ name, as a convenience, it's not the _current_ name,
and is not defined as such.  The whole point is that if you su to
another account, LOGNAME can persist as the original.  It's not
_trustworthy_, but might be used to let you have a .zshrc.staff.$LOGNAME
file which might be auto-sourced, or whatever else you want.

If you do:

    % typeset +x LOGNAME

then LOGNAME won't be exported.

> erik@virtubsd:~% su - root
> Password:
> virtubsd# echo $LOGNAME
> erik

Yup, that's exactly what it's supposed to do.

You might want USERNAME instead of LOGNAME ?

-Phil



Messages sorted by: Reverse Date, Date, Thread, Author