Bash startup scripts

Bash startup scripts or files are used by the shell program /bin/bash to create a shell environment. Each script has a specific use and affects the login environment differently. Every subsequent script executed can override the values assigned by previous scripts.

The startup scripts used by Bash are.
1)  ~/.bashrc
2)  /etc/bashrc
3)  ~/.bash_profile
4)  ~/.bash_login
5)  ~/.profile
6)  /etc/profile
7)  /etc/profile.d/*

 

1)  ~/.bashrc

 

2)  /etc/bashrc

 

3)  ~/.bash_profile

  • User specific startup script.
  • Used for setting Environment variables and running Commands.
  • Called by the login process, during the creation of Login shells.
  • Calls the script ~/.bashrc.

 

4)  ~/.bash_login

  • User specific startup script.
  • Used for setting Environment variables and running Commands.
  • Called by the login process, if ~/.bash_profile is not present, during the creation of Login shells.
  • Maintained for compatibility with C shell and Tenex C shell startup script, ~/.login.

 

5)  ~/.profile

  • User specific startup script.
  • Used for setting Environment variables and running Commands.
  • Called by the login process, if ~/.bash_profile and subsequently ~/.bash_login are not present, during the creation of Login shells.
  • Maintained for compatibility with Bourne shell and Korn shell startup script, ~/.profile.

 

6)  /etc/profile

  • Global startup script.
  • Used for setting Environment variables and running Commands.
  • Called by the login process, during the creation of Login shells.
  • Calls the scripts in the directory /etc/profile.d/.

 

7)  /etc/profile.d/*

  • Directory containing global startup scripts.
  • Used for setting Environment variables and running Commands.
  • Called by the script /etc/profile, during the creation of Login shells.
    Called by the script /etc/bashrc, during the creation of Non-Login shells.

 

 

 

It is recommended to view the following sections also.
Difference between Login shell and Non Login shell
Difference between Local Variables and Environment Variables