[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: "screen" will not read /etc/profile




On Wed, Jan 09, 2002 at 11:01:39AM +0800, Patrick Hsieh wrote:
> I have set some aliases in /etc/profile, but
> when I enter "screen" and create a new "screen" session,
> it does not work, I am afraid screen will not read /etc/profile.
> Idea?

Screen doesn't read profile or .bashrc, bash does.
Screen causes a shell (bash) to be run, and then bash is
failing to read your /etc/profile.

This is because you have already logged in, and you are
running a bash that only reads bashrc (not a "login" bash).

According to the man page (bash(1)), if you run a login bash,
it will execute /etc/profile, if it exists, then it will
run a user-specific version of it (such as $HOME/.bash_profile,
$HOME/.bash_login or $HOME/.profile) if that exists.  When you
run an interactive non-login bash, it will run $HOME/.bashrc
if one exists.  It's actually more complicated than that,
but this describes the defaults.

You could set your aliases from .bashrc.  If you want them to
be system-wide, you can make a file /etc/bash.bashrc (if it's
not already there) and source that file from your $HOME/.bashrc.
You'll have to have a $HOME/.bashrc that sources /etc/bash.bashrc
for every user.  That's actually pretty easy to do:  before
you create the new users, put a line in /etc/skel/.bashrc
to source the /etc/bash.bashrc, and when you create new users
they will have a copy of all the files in /etc/skel.


Generally, /etc/profile is for things that can be inherited
from one shell to a subshell (such as environment variables),
and bashrc is for things that must be run in each shell
(whether login ones or not).  It is common to call
$HOME/.bashrc from the $HOME/.login file, so that the
first shell (the login shell) will have all the stuff set
that the subshells have (from .bashrc).  This is a simplification
also:  there are some commands you don't want to run if you
are running a non-interactive shell.  See the man page,
and the examples in /usr/share/doc/bash/examples/startup-files.

Hmm, that's strange, I found the above reference in
/etc/skel/.bashrc, but did not find an examples directory
in /usr/share/doc/bash.  Odd... Oh well, the scripts in
/etc/skel are good examples.

-- 
bjb@achilles.net
Welcome to the GNU age!   http://www.gnu.org



Reply to: