How to determine the level of subshell you are in.
Lately I have been using aws-vault to manage my session across multiple AWS accounts. This tool puts you in a subshell, but after some time I forget if this particular terminal session is a subshell or not. The $SHLVL
variable tracks your shell nesting level.
$ echo $SHLVL
1
$ bash
$ echo $SHLVL
2
$ exit
$ echo $SHLVL
1
I now include this in my $PS1
prompt for ease of use.