How to reload .bash_profile from the command line
Overview
The .bash_profile is one of the startup files used by bash shell to set up the shell configuration.
In some systems, we may not find the file .bash_profile. In such cases, the shell looks for the file .profile.
We can also create the file .bash_profile and define functions or environment variables in it.
We can use the syntax below to reload the .bash_profile.
. ~/.bash_profile
Let's look at an example of this.
Example
#move to directorycd ~/#create bash profiletouch .bash_profile#write into bash profile filecat > .bash_profile <<- EOMecho "Bash Profile execution starts.."URL="https://www.educative.io/"echo "Bash Profile execution stops.."EOM#reload the bash profile. ~/.bash_profile
Explanation
In the code snippet above:
- Line 5: We create a file
.bash_profilesince it is not available in this system. - Lines 8–12: We create an environment variable and a few echo statements in the
.bash_profilefile. - Line 15: We reload the
.bash_profilefile using the command. ~/.bash_profile.
After executing the terminal, we can see that the bash profile is reloaded. We can use echo $URL to print the environment variable value that we defined in the .bash_profile file.