I logged in to Debian 7 via SSH, not as root
. When writing sudo
all the time became too much overhead, I did sudo su
. Since the Debian default shell (dash
?) does not support the Tab key to complete filenames, I ran /bin/bash
. I added a few aliases to .bash_aliases
and to activate them, I ran /bin/bash
again (potentially a few more times) until I got all aliases right.
After doing some more system setup, I could not remember any more how many times I have to type exit
to get back to the beginning but not logging out from SSH.
Actually this is not a big deal, since I could log in via SSH again, so this is more an academic question. I wondered if there is a way to find out
- what exactly
exit
will exit, so I could at least check each time before I type it - how many times I can
exit
until the user is logged out completely
I tried man exit
but it seems there is no manual available. help exit
doesn't tell much either.
I first thought I could find a possible solution using pstree
, but IMHO it lists sshd
too often and sudo su
is missing.
:~$ pstree | grep ssh
|-sshd---sshd---sshd---sh---bash---bash-+-grep
Best Answer
You can use the
SHLVL
variable to determine how far nested in you're, to a shell started by a login process:Since the login shell from
su -
clearsSHLVL
, it hasSHLVL=1
. To quit the nearest such login shell in the shell ancestry, you have to useexit
$SHLVL
times.SHLVL
is not supported bydash
, so whenever it enters the picture, the figure will be wrong. However,dash
isn't the login shell for any usable account on Ubuntu, andSHLVL
works on more advanced shells likebash
andzsh
.I cannot reproduce your missing
sudo su
: