How to find out bash shell nesting level or a nested shell level

Fig. 02: Bash shell nesting level (subshell numbers)

Fig. 02: Bash shell nesting level (subshell numbers)

The syntax is as follow for bash to display nesting level each type you start a subshell:

bash
echo "$SHLVL"
zsh
echo "$SHLVL"
ksh
echo "$SHLVL"
exit
echo "$SHLVL"
exit 
echo "$SHLVL"

Examples and usage: A Shell Primer: Master Your Linux, OS X, Unix Shell Environment

Leave a Comment