I occassionally need to start bash more than once, and typically use exit (my .bash_profile is set to ignore ^D (EOF)) to leave the new version of bash. Periodically I hit exit one too many times, which causes my terminal session (and debugging sessions) to dissappear. Since this caused me a good deal of grief yesterday, I decided to find a fix in the bash documentation. After reading for 30-minutes or so, I came across the bash SHLVL variable:
$ echo SHLVL
1
$ bash
$ echo SHLVL
2
$ bash
$ echo SHLVL
3
$ exit
$ echo SHLVL
2
This is a useful variable, and I plan to make a “shellami” alias. Tight!