Linux
10 April 2012 0 Comments

About .bashrc, .profile, .bash_profile and .bash_login

How it works

There are various files that may be executed by the Bash shell when it is started. Usually they follow this logic:

  • When bash is invoked as an interactive login shell:
    1. Bash first reads and executes commands from the file /etc/profile, if that file exists.
    2. 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. Usually there is a default ~/.profile file, and ~/.bash_profile and ~/.bash_login usually do not exist.
  • When bash is invoked as an interactive non-login shell:
    1. Bash reads and executes commands from /etc/bash.bashrc and ~/.bashrc, if these files exist.
    2. The standard ~/.profile sources (runs) ~/.bashrc if it exists.

A login shell means a session where you directly log into a system, e.g. setting up a remote SSH session or logging in through a non-graphical text terminal. A non-login shell is then the type of shells you open after logging in: typically in a graphical session when you open a new terminal window.

The bottom line is that you should put customisations that should always be executed in ~/.bashrc!
Example

Example: After installing…

Tags: ,