[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] How to figure out what files has been loaded by bash?
From: |
Bob Proulx |
Subject: |
Re: [Help-bash] How to figure out what files has been loaded by bash? |
Date: |
Sun, 4 Jan 2015 11:51:16 -0700 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
Peng Yu wrote:
> I try to login to an linux account (with bash as the login shell)? But
> it somehow hangs before getting to loading .bashrc file (as I put an
> echo statement in the first line of .bashrc but nothing is printed to
> the screen). Is there a way debug what files has been loaded in the
> login process so that I can figure how what causes the problem?
A useful debug technique is:
ssh -t localhost bash -ix
That will trace every command executed at login time.
The bash documentation includes an extensive section describing what
files are sourced. Unfortunately due to legacy shell compatibility it
isn't a completely simple process.
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.
Note that .bashrc is NOT sourced at login time. The ~/.bash_profile
et al files are sourced at login time. In your ~/.bash_profile or
~/.profile include a statement to source the ~/.bashrc file.
For example I have this in my ~/.profile and share it among bash, ksh,
zsh, and sh. All of those read ~/.profile.
export LANG=en_US.UTF-8
export LC_COLLATE=C
PATH=$HOME/bin:$PATH
if [ -n "$BASH_VERSION" ]; then
. "$HOME/.bashrc"
fi
Obviously if you only care about bash then that can be simplified.
But I am always encouraging generality. :-)
export LANG=en_US.UTF-8
export LC_COLLATE=C
PATH=$HOME/bin:$PATH
. "$HOME/.bashrc"
Bob