Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Sep 2007 18:31:19 +0300
From:      Giorgos Keramidas <keramida@ceid.upatras.gr>
To:        Albert Shih <Albert.Shih@obspm.fr>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: bash on login.
Message-ID:  <20070906153119.GB2498@kobe.laptop>
In-Reply-To: <20070906150602.GE61602@pcjas.obspm.fr>
References:  <20070906150602.GE61602@pcjas.obspm.fr>

next in thread | previous in thread | raw e-mail | index | archive | help
On 2007-09-06 17:06, Albert Shih <Albert.Shih@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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20070906153119.GB2498>