Skip to content

Instantly share code, notes, and snippets.

@hfreire
Last active February 9, 2025 16:07
Show Gist options
  • Select an option

  • Save hfreire/94a7c0cdd7b0f603a6f1dd6acfd7213f to your computer and use it in GitHub Desktop.

Select an option

Save hfreire/94a7c0cdd7b0f603a6f1dd6acfd7213f to your computer and use it in GitHub Desktop.

Revisions

  1. hfreire revised this gist Dec 10, 2019. No changes.
  2. hfreire renamed this gist Dec 10, 2019. 1 changed file with 9 additions and 3 deletions.
    12 changes: 9 additions & 3 deletions gistfile1.txt → bash_startup_load_order.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,12 @@
    If you have ever put something in a file like .bashrc and had it not work, or are confused by why there are so many different files — .bashrc, .bash_profile, .bash_login, .profile etc. — and what they do, this is for you.
    The issue is that Bash sources from a different file based on what kind of shell it thinks it is in. For an “interactive non-login shell”, it reads .bashrc, but for an “interactive login shell” it reads from the first of .bash_profile, .bash_login and .profile (only). There is no sane reason why this should be so; it’s just historical. Follows in more detail.
    For Bash, they work as follows. Read down the appropriate column. Executes A, then B, then C, etc. The B1, B2, B3 means it executes only the first of those files found.
    If you have ever put something in a file like .bashrc and had it not work, or are
    confused by why there are so many different files — .bashrc, .bash_profile, .bash_login,
    .profile etc. — and what they do, this is for you.
    The issue is that Bash sources from a different file based on what kind of shell it thinks
    it is in. For an “interactive non-login shell”, it reads .bashrc, but for an “interactive
    login shell” it reads from the first of .bash_profile, .bash_login and .profile (only).
    There is no sane reason why this should be so; it’s just historical. Follows in more detail.
    For Bash, they work as follows. Read down the appropriate column. Executes A, then B, then C,
    etc. The B1, B2, B3 means it executes only the first of those files found.

    +----------------+-----------+-----------+------+
    | |Interactive|Interactive|Script|
  3. hfreire created this gist Dec 10, 2019.
    28 changes: 28 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    If you have ever put something in a file like .bashrc and had it not work, or are confused by why there are so many different files — .bashrc, .bash_profile, .bash_login, .profile etc. — and what they do, this is for you.
    The issue is that Bash sources from a different file based on what kind of shell it thinks it is in. For an “interactive non-login shell”, it reads .bashrc, but for an “interactive login shell” it reads from the first of .bash_profile, .bash_login and .profile (only). There is no sane reason why this should be so; it’s just historical. Follows in more detail.
    For Bash, they work as follows. Read down the appropriate column. Executes A, then B, then C, etc. The B1, B2, B3 means it executes only the first of those files found.

    +----------------+-----------+-----------+------+
    | |Interactive|Interactive|Script|
    | |login |non-login | |
    +----------------+-----------+-----------+------+
    |/etc/profile | A | | |
    +----------------+-----------+-----------+------+
    |/etc/bash.bashrc| | A | |
    +----------------+-----------+-----------+------+
    |~/.bashrc | | B | |
    +----------------+-----------+-----------+------+
    |~/.bash_profile | B1 | | |
    +----------------+-----------+-----------+------+
    |~/.bash_login | B2 | | |
    +----------------+-----------+-----------+------+
    |~/.profile | B3 | | |
    +----------------+-----------+-----------+------+
    |BASH_ENV | | | A |
    +----------------+-----------+-----------+------+
    | | | | |
    +----------------+-----------+-----------+------+
    | | | | |
    +----------------+-----------+-----------+------+
    |~/.bash_logout | C | | |
    +----------------+-----------+-----------+------+