Linux, Unix, and MacOS operating systems provide the bash shell in order to provide a command-line environment and shell. The bash shell has different configurations which can be configured using the
.bash_profile files. The .bash and .bash_profile files can be used to set different bash configurations like $PATH, history, alias, command prompt, etc. But why there are two different bash configuration files named
The .bashrc file is located under every user’s home directory. The .bashrc file location can be expressed like
~/.bashrc . The .bashrc file is executed when a non-login bash shell is started. A typical .bashrc file is like below which sets some configuration like below.
.bash_profile file is executed for the login shells. When a user logins using his username or password the .bash_profile file is executed in order to configure the bash shell. The .bash_profile file is generally used by the MacOS operating systems but can be also used in Linux and Unix. But the Linux operating systems generally do not provide the .bash_profile by default.
.bashrc vs .bash_profile
The .bash_profile is called only for interactive logins using a username which generally occurs during ssh, GUI, or terminal login. The .bashrc is called every time a new shell is opened. This happens a lot of times after a user logins to his account. The .bashrc is not called during user login by default.
Call .bash_profile From .bashrc File
As the .bash_profile is not called only during user login by default we may need to use the .bash_profile file for the user’s new shells. The most popular way is using the .bash_profile file. The following code snippet can be used to run .bash_profile via the .bashrc file.
if [ -f ~/.bash_profile ]; then source ~/.bash_profile fi