su doesn't read user's shell init files?

su doesn't read user's shell init files?

Post by Chad Pankra » Thu, 31 Aug 1995 04:00:00

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)


Chad Pankratz


1. 'su --login user -c command' doesn't run loggin scripts

hello, i have a Mandrake 7.0

'su --login user -c command' doesn't run loggin scripts

it does not read the .bash_profile !

Wed Feb 16 15:50:35 CET 2000


total 24
drwxr-xr-x   2 postgres postgres     4096 Feb 16 15:50 ./
drwxr-xr-x  13 root     root         4096 Feb 16 15:48 ../
-rw-------   1 postgres postgres     1568 Feb 16 11:49 .bash_history
-rw-r--r--   1 postgres postgres      177 Feb 16 11:49 .bash_profile
-rw-r--r--   1 postgres postgres      177 Feb 15 17:32 .bashrc

this works fine on redhat 6.

Wed Feb 16 16:06:43 CET 2000


total 45
drwxr-xr-x  20 postgres postgres     1024 Feb 16 16:06 .
-rw-r--r--   1 postgres postgres      256 Feb 16 16:06 .bash_profile
-rw-r--r--   1 postgres postgres     1448 Feb 16 16:06 .bashrc
drwxr-xr-x  32 root     root         1024 Feb 16 15:00 ..
-rw-------   1 postgres postgres    14343 Feb 16 10:39 .bash_history

is it a bug or a feature ?


2. Question on Mount...

3. su'ing doesn't read /.cshrc

4. SUID - just how evil is it?

5. user shell doesn't read /etc/profile

6. redirect stdout & stderr to variable

7. 'su ' vs. 'su -'

8. Unix - Frequently Asked Questions (Contents) [Frequent posting]

9. restrict use of 'su' or 'su -'

10. 'su -c' doesn't work properly?

11. Path as "su" doesn't equal path as root or as login user

12. users have su priv's but su fails

13. LinuxPPC99: 'INIT: ld ''x'' respawning too fast...'??