Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I found that those are .bash_profile, .bashrc, .bash_login, .profile.

What's the reading sequence between them?

share|improve this question
See the INVOCATION section of the bash manual. Meanwhile I am sure this is a duplicate of something. – jw013 Jul 25 '12 at 16:44
Try to do some research before asking, man bash contains all the information – Ulrich Dangel Jul 25 '12 at 16:48
From man bash, non-interactively means non-login shells? Thank you~ – sam Jul 25 '12 at 16:57
@jw013 Nearest thing to a duplicate I can find is Difference between .bashrc and .bash_profile on superuser.com. – Mikel Jul 25 '12 at 19:14
@jw013 unix.stackexchange.com/questions/3052/alternative-to-bashrc and unix.stackexchange.com/questions/40708/… but neither fully addresses this question – Gilles Jul 25 '12 at 23:25

Basically, if it's a login shell it sources /etc/profile then .bash_profile. If it's not a login shell, but you're at a terminal, it sources /etc/bash.bashrc then .bashrc.

But it's actually a lot more complicated.

The way I read the man page:

if bash_mode; then
    if login_shell; then
        if test -e /etc/profile; then source /etc/profile; fi
        if test -e .bash_profile; then source .bash_profile
        elif test -e .bash_login; then source .bash_login
        elif test -e .profile; then source .profile; fi
    elif interactive_shell || remote_shell; then
        if test -e /etc/bash.bashrc; then source /etc/bash.bashrc
        if test -e .bashrc; then source .bashrc; fi
    elif test -n "$BASH_ENV"; then
        source "$BASH_ENV"
elif sh_mode; then
    if login_shell; then
        if test -e /etc/profile; then source /etc/profile; fi
        if test -e .profile; then source .profile; fi
    elif interactive_shell; then
         if test -n "$ENV"; then
             source "$ENV"

It's a login shell any time the shell is run as -bash (note the minus sign) or with the -l option. This usually happens when you log in using the login command (Linux virtual consoles do this), over ssh, or if your terminal emulator has the "login shell" option enabled.

It's an interactive shell any time standard input is a terminal, or bash was started with the -i option. Note that if the shell is also a login shell, bash doesn't check if the shell is interactive. For this reason, .bash_profile usually contains code to source .bashrc, so you can share the same settings between interactive and login shells.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.