Completely restart Bash

53,334

Solution 1

Have it replace itself with itself.

exec bash -l

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

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

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

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

Share:
53,334
Naftuli Kay
Author by

Naftuli Kay

Updated on September 18, 2022

Comments

  • Naftuli Kay
    Naftuli Kay over 1 year

    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.

  • Naftuli Kay
    Naftuli Kay over 12 years
    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.
  • Arcege
    Arcege over 12 years
    Take out the exec and you get a shell that sources the files that you want. Then just exit when you are done checking.
  • Ignacio Vazquez-Abrams
    Ignacio Vazquez-Abrams over 12 years
    @TK: Any variables you assign will take precedence over the ones left over from the previous shell.
  • Naftuli Kay
    Naftuli Kay over 12 years
    So this will work for changing my Bash prompt? Ie, it'll reload my bash prompt each time I run it?
  • Ignacio Vazquez-Abrams
    Ignacio Vazquez-Abrams over 12 years
    As long as you're setting $PS1 in bash's startup files, yes.
  • Sardathrion - against SE abuse
    Sardathrion - against SE abuse over 12 years
    +10, a clean shell where you can change edits is essential.
  • Naftuli Kay
    Naftuli Kay over 12 years
    I'm in a DE, so it shouldn't be so bad, Bauhaus yes, be careful.
  • underscore_d
    underscore_d over 8 years
    important note: "a fresh shell" here means a shell within your existing shell, so you are only nesting shells, not replacing your original one. The accepted answer does that properly.
  • Elliptical view
    Elliptical view over 6 years
    On my screen in Firefox, l (the letter ell) and 1 (the numeral one) look similar. This is bash dash ell, not bash dash one.
  • Ignacio Vazquez-Abrams
    Ignacio Vazquez-Abrams over 6 years
  • Dan Nissenbaum
    Dan Nissenbaum almost 4 years
    It would be nice if the answer included what the -l does to save time looking it up.