Restart terminal without closing on MacOS

blagus picture blagus · Jul 30, 2019 · Viewed 18.6k times · Source

How to restart my current MacOS terminal session without closing the window?

In Linux I use exec bash but it does not work in this environment. I made a few changes to the .bash_profile (prompt, alias etc) I would like to see without closing it and opening again.

thanks in advance

Answer

Mihir Luthra picture Mihir Luthra · Jul 30, 2019

Just type in the command:

exec bash -l

I guess that should do it.

For zsh,

exec zsh -l

This is needed because every shell on macOS by default is a login shell.

Justing writing exec bash would replace the current shell with a non-login shell which is not the same effect as closing and re-opening the terminal.

exec would make new bash -l process replace the current shell. If exec is not used, bash -l would spawn a new shell over the current shell incrementing the $SHLVL.