Re: PS1 issue


Subject: Re: PS1 issue
From: Simon Hill (ibis@metasystema.org)
Date: Thu May 25 2000 - 19:59:04 MDT


Hi Josh, Ryan,

Yes, that is the way it works. /etc/profile and .bash_profile are only run
for login shells, which is not the default for xterms and various other
terms. I ran into this some time ago... I have seen an opinion stated
somewhere shell variables (especially PATH) should be defined in the
profile files rather than the shell's rc file. Many people try to follow
this, but it doesn't work well... if you happen to use more than one
shell, possibly for different purposes, it makes more sense to put them in
the shell's rc file.

There was (still is?) a note in Red Hat's /etc/bashrc saying:

# For some unknown reason bash refuses to inherit
# PS1 in some circumstances that I can't figure out.
# Putting PS1 here ensures that it gets loaded every time.

But the reason is known: /etc/profile doesn't get run for a non-login
shell. There was (may still be) a similar problem which affects using the
command 'xon' to start an x-client on a remote machine. /usr/bin/X11 was
(is?) added to the path in /etc/profile, but when you start an x-client
with xon, it is not a login shell, so /etc/profile doesn't get run, X is
never added to the path and the command fails. If you add /usr/X11/bin to
the path in the shell rc file, then xon works as intended.

In any case, for the bash shell the sequence is:

If login: 1. /etc/profile
           2. .bash_profile
           3. .bashrc (note: this is sourced by .bash_profile,
                                        NOT read by bash!)
           4. /etc/bashrc (note: this is sourced by .bashrc,
                                        NOT read by bash!)

If non-login: bash reads .bashrc INSTEAD of .bash_profile, thus only steps
3 and 4 are executed, and step four is explicitly called by .bashrc
(something that leaves you at the mercy of your sysadmin ;-)

So, the only thing that .bash_profile seems to be good for is to set
variables and aliases that you ONLY want defined if the shell is a login
shell. I'm not sure whether there is a use for this...

Regards,

Simon Hill (simon@metasystema.org)
http://www.metasystema.org/

On Thu, 25 May 2000, Josh Smith wrote:

> RG> Ok, I've read and re-read the previous threads on this topic and maybe
> RG> someone else is or has experienced the same problem. I have the prompt I
> RG> want to use in both the .bash_profile and also in /etc/profile, yet I
> RG> still have to re-source .bash_profile every time I open up a new
> RG> terminal window.
>
> I think bash only reads /etc/profile and ~/.bash_profile for "login" shells,
> which an xterm window may not be.
>
> I personally remove /etc/profile, /etc/bashrc, /etc/csh.cshrc, and
> /etc/csh.login, and just use the files in my home directory. I then put the
> stuff I want into ~/.bashrc, and make ~/.bash_login a symlink pointing to
> that (i.e. 'ln -s .bashrc ~/.bash_login). That seems to work for both login
> and "non-login" shells.
>
> -Josh (irilyth@infersys.com)
>



This archive was generated by hypermail 2a24 : Thu May 25 2000 - 19:55:25 MDT