bash on login.
Giorgos Keramidas
keramida at ceid.upatras.gr
Thu Sep 6 08:31:52 PDT 2007
On 2007-09-06 17:06, Albert Shih <Albert.Shih at obspm.fr> wrote:
> Hi all
> I'm using bash for standard shell, what I don't understand is when I'm
> connect by ssh on my server the bash don't parse .bashrc file.
Because .bashrc is not loaded by login shells. Read the manpage of
bash(1) for more details, and make sure you pay A LOT of attention
to the ``INVOCATION'' section:
When bash is invoked as an interactive login shell, or as a
non-interactive shell with the --login option, it first reads
and executes commands from the file /etc/profile, if that
file exists. After reading that file, it looks for
~/.bash_profile, ~/.bash_login, and ~/.profile, in that
order, and reads and executes commands from the first one
that exists and is readable. The --noprofile option may be
used when the shell is started to inhibit this behavior.
When a login shell exits, bash reads and executes commands
from the file ~/.bash_logout, if it exists.
When an interactive shell that is not a login shell is
started, bash reads and executes commands from ~/.bashrc, if
that file exists. This may be inhibited by using the --norc
option. The --rcfile file option will force bash to read and
execute commands from file instead of ~/.bashrc.
> But if in the bash session I type «bash» this time the .bashrc is use.
Yes. This is no longer a login shell. It's merely an interactive
shell, so bash ignores .bash_profile and reads .bashrc instead.
> How can I make the .bashrc file is read when I connect by ssh ?
My preferred setup uses both files.
The .bash_profile file acts solely as a 'delegation script', which loads
all my preferences from .bashrc. The full contents of my .bashrcc file
are something like this:
test -f ~/.bashrc && . ~/.bashrc
true
All my preferences, options, environment variables, and other bash
configuration is stored in ~/.bashrc.
This way both login shells and interactive shells use precisely the same
environment.
- Giorgos
More information about the freebsd-questions
mailing list