Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

up vote 7 down vote accepted

Have it replace itself with itself.

exec bash -l

Note that this won't affect things such as the cwd or exported variables.

share|improve this answer
    
Nice, but I'd especially like to do this in order to check and see if my PATH is being set as I want or my PS1, etc. –  Naftuli Tzvi Kay Oct 16 '11 at 22:35
1  
Take out the exec and you get a shell that sources the files that you want. Then just exit when you are done checking. –  Arcege Oct 17 '11 at 0:20
    
@TK: Any variables you assign will take precedence over the ones left over from the previous shell. –  Ignacio Vazquez-Abrams Oct 17 '11 at 3:23
    
So this will work for changing my Bash prompt? Ie, it'll reload my bash prompt each time I run it? –  Naftuli Tzvi Kay Oct 17 '11 at 3:35
    
As long as you're setting $PS1 in bash's startup files, yes. –  Ignacio Vazquez-Abrams Oct 17 '11 at 3:40

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).

share|improve this answer
    
+10, a clean shell where you can change edits is essential. –  Sardathrion Oct 17 '11 at 13:17
    
I'm in a DE, so it shouldn't be so bad, Bauhaus yes, be careful. –  Naftuli Tzvi Kay Oct 17 '11 at 17:12
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).

share|improve this answer

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...

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.