Is there a way to completely restart Bash and reload .bashrc and .profile and the like? I’d like to make sure my changes worked out properly after editing these files.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Have it replace itself with itself.
exec bash -l
Note that this won’t affect things such as the cwd or exported variables.
Method 2
I urgently suggest to log in on a separate window/screen. This way you still have a working session if something goes wrong with your changes to startup files. Also you are sure to have a clean environment.
Reason: I saw too many people locking themselves out of a system because of a simple typo in their .profile (or such).
Method 3
If your goal is simply to read the modified files again, you don’t have to restart it. You can simply source it.
source filename
or
. filename # notice the dot
Note that this won’t give you a “clean state” in a sense that it won’t unset any set variables or defined functions…
Method 4
su -l yourOwnUserName
Will open a fresh shell for yourOwnUserName user with all the settings re-loaded. This is shell-independent, as it refers to system settings, not your specific shell. It also loads some system-wide settings that bash -l does not (like user groups).
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0