What’s the difference between .bash_profile and .bashrc?

What’s the difference between .bash_profile and .bashrc?

In this tutorial I will tell you the difference between .bash_profile and .bashrc, so what’s the difference between .bash_profile and .bashrc?

When you log into a Unix system, the system starts the shell that is set as default. The bash shell reads the ~/.bash_profile at login and if this file is missing or corrupt, the shell tries reading ~/.profile.

Only the login shells read the ~/.profile file. The/bin/false shell, for example, doesn’t.

When you start bash (type bash or /bin/bash in the terminal), the ~/.bashrc file will be read, except when the bash is invoked as the default shell and the ~/.bash_profile or ~/.profile files are read.

So, in the ~/.bashrc file you can put your aliases, functions, or your custom prompt configuration. It is better to add this line in your ~/.bash_profile (if you don’t already have it) , to invoke the ~/.bashrc and the ~/.profile files  when the ~/.bash_profile is read:

if [ -r ~/.profile ]; then . ~/.profile; fi
case "$-" in *i*) if [ -r ~/.bashrc ]; then . ~/.bashrc; fi;; esac

You can also put the scripts you want to start at login, in the ~/.bash_profile file.

There is also a /etc/bash.bashrc file. In the /etc/bash.bashrc place the commands you want to be available for all the users in the system (for example: a PATH to a script that all the users in the system need to use.)

When you login from the GUI, the ~/.profile isn’t always read by the shell. This depends also on the desktop environment used.

Was this Tutorial helpful? Help others share on Facebook, Twitter, and Google Plus!
 
Enjoyed this video?
What's the difference between .bash_profile and .bashrc?
"No Thanks. Please Close This Box!"