Reset / Reboot bash completely (alias and function)

I want to reset the shell, when I exit / , reloading aliases, functions, from scratch.

But don't talk about source ~/.bashrc and . ~/.bashrc . ~/.bashrc !

Why? Because source or . they simply enrich the current shell with new functions, aliases, etc.


FYI, you can put this function in your bashrc:

 function foo { echo "foo"; } 

Then do source ~/.bashrc or . ~/.bashrc . ~/.bashrc . Yes, foo works. Then now edityour .bashrc and replace foo with bar to have:

 function bar { echo "bar"; } 

Now you can enter foo and see that the foo function still works , even though it no longer exists in the .bashrc . This is what I wanted to show.


I tried exec bash; but it does not load the .bashrc . And exec bash;source ~/.bashrc; obviously does not work, because exec kills the current process ( source never called).

+4
source share
2 answers

like desire OP

 bash --login 

Note: if you use bash inside the terminal (xterm or similar), you also need to provide the -ls (or equivalent) to the terminal. (e.g. xterm -ls )

+7
source

Enter the following script:

 while true; do bash if [ $? -ne 123 ]; then break fi done 

Set the executable bit and set it as a shell. Then add an alias to ~/.bashrc :

 alias resetterm="exit 123" 

This requires only one additional bash process that runs all the time. Each time you reset, a new bash starts, and the old process ends.

+1
source

All Articles