I've looked around and bit for an answer to this question but I don't seem to find it (which is weird).
My question is, is there any simple way to restart the BASH session from within the terminal on Mac. I just want the same behaviour as if I closed the terminal application and started it again (all variables reset, .bash_profile
sourced etc).
I know how to source .bash_profile
, but that's not what I want. One of the reasons I want to do this is because a plugin for my BASH prompt has code that prevents colors from being loaded multiple times. Therefore, sourcing .bash_profile
doesn't reload the color variables and I have to restart the terminal application to get changes in effect.
exec bash
only restart that interactive shell then? Also, can you explain exactly what the exec command does and it's options? Thanks! – Mattias Jul 23 '15 at 15:38man bash
, find the last instance of the string SHELL BUILTIN COMMANDS and then scroll down to exec. In short, passing the-c
flag will run it without any environment variables (which might be required for your purposes, I don't know), and the other arguments -l and -a are probably not things you want (they seem to be historical/obscure and specific features). You can also use exec for opening new file descriptors in the current shell, if you leave off the command. – Muzer Jul 23 '15 at 15:44-l
here is an argument to bash and just makes it behave like a login shell. Opening file descriptors in the current shell has nothing to do with your question, but you can useexec 4<>test.txt
for example to make file descriptor 4 point to test.txt. Then in the rest of your shell you can doecho test>&4
to output to test.txt. – Muzer Jul 23 '15 at 15:57bash --login
– Pasupathi Rajamanickam Jul 13 '18 at 15:34exec -c
will clear the environment before running whatever command you specify. I can edit the answer to add this if you want. – Muzer Aug 08 '18 at 16:27