How can I determine if I have a child shell?

If I use bash and type bash , I hit the child shell and you need to type exit to return to the original parent shell. If I forget what I'm on, how can I check?

+5
source share
2 answers

Use the SHLVL environment SHLVL .

man bash:

SHLVL : incremented each time a bash instance starts.

 $ echo "$SHLV" 1 $ bash $ echo "$SHLV" 2 $ exit $ echo "$SHLV" 1 
+8
source

This is a lower answer, but you can also use pstree:

 $ pstree -s $BASHPID systemd───systemd───gnome-terminal-───bash───pstree $ bash $ pstree -s $BASHPID systemd───systemd───gnome-terminal-───bash───bash───pstree 
+2
source

Source: https://habr.com/ru/post/1268524/


All Articles