How can I reload file .bash_profile from the command line? I can get the shell to recognize changes to .bash_profile by exiting and logging back in, but I would like to be able to do it on demand.
To apply changes made to the .bash_profile
file in the current terminal session without logging out and back in, you can use the source
command or its shorthand, which is the dot .
. These commands will read and execute the contents of the file, making the changes take effect immediately.
Here's how you can do it:
Using
source
:sh
source ~/.bash_profile
Using the dot .
:
sh
. ~/.bash_profile
In both cases, replace ~/.bash_profile
with the actual path to your .bash_profile
file.
Here's an example scenario:
Assuming you've made changes to your .bash_profile
file, like adding an environment variable or an alias, and you want to apply those changes without logging out:
Edit your
.bash_profile
using a text editor.Save the changes.
To apply the changes immediately in the current terminal session, use either of the following commands:
sh
source ~/.bash_profile
or
sh
. ~/.bash_profile
The changes you made to the .bash_profile
file will now be active in your current terminal session.
Remember that the changes will only apply to the terminal session in which you run the source
or .
command. If you open a new terminal window or session, you'll need to run the command again to apply the changes.
Comments
Post a Comment