The difference between .bashrc and .bash_profile lies in when they are executed and the type of shell session they are associated with:
.bashrc
- Purpose: It is executed for interactive non-login shells.
- Usage: Typically used for setting up the environment for terminal sessions that are opened after logging in (like opening a new terminal window).
- Common Configurations: Aliases, functions, and other shell settings that you want available in every interactive shell.
.bash_profile
- Purpose: It is executed for login shells.
- Usage: This file is read and executed when you log into your system (e.g., via a terminal or SSH).
- Common Configurations: Environment variables, including
PATH, and commands that should run only once at the start of the session.
Key Points
- If you want to ensure that settings in
.bashrcare available in login shells, it's common to source.bashrcfrom.bash_profileby adding the following line to.bash_profile:if [ -f ~/.bashrc ]; then . ~/.bashrc fi
This way, you can maintain a consistent environment across both types of shell sessions.
