Hi. We have just upgraded from SunOS 4.1.3 to Solaris 2.4, and I am a
little confused about the su command. I realize that "su - user"
invokes a login session of that user's shell, but a plain "su user"
appears not to read ANY of that user's interactive shell
initialization files (i.e. .cshrc, .bashrc, .zshrc). Is there a way
to get su to do this?
Specifically, (using a Z shell example), I've got a .zshrc in / for
root's account. If I login as some user, and do a "su", this .zshrc
does NOT get sourced. From what I can tell, the system-wide
/etc/zshrc gets sourced, then the original user's .zshrc (since the su
command doesn't change the environment, therefore $HOME still refers
to the original user's home dir). I've experimented with zsh, bash,
and csh (and their respective init files), so the problem doesn't seem
to be shell specific.
Why don't I use "su -"? Well, that does what I want it to do, but the
login process causes the directory to be changed to root's home
directory, which is rather annoying since I'll have to delve back into
the directory I was in before I issued the su command. I guess, then,
my main question is: Is there a way to have "su user" change to the
new user's environment, but not act as a login shell? In this case,
"su" would properly set up root's home directory, etc., but then just
execute the interactive shell init file (i.e. .zshrc) and not the
login file (.zlogin or .login). If not, is there a replacement su
command I can get?
I suppose I'm just gonna end up setting up some kind of su function to
save the current directory and whatever else the login process will
cause to be forgotten, call "su -", and then restore the directory and
whatever else (if anything). I just thought I'd ask if there's an
easier/better way, and to see if anyone else finds this behavior as
questionable as I do. (I don't recall it being a problem under 4.1.3)