Doing some tests, I discovered that setting the bash shebang in a script would cancel the $BASH_SUBSHELL behavior.
# in the terminal $ echo $BASH_SUBSHELL 0 $ (echo $BASH_SUBSHELL) 1 script_no_shebang.sh
echo $BASH_SUBSHELL $ ./script_no_shebang.sh 0 $ test=$(./script_no_shebang.sh) $ echo $test 1 script_shebang.sh
#!/bin/bash echo $BASH_SUBSHELL $ ./script_shebang.sh 0 $ test=$(./script_shebang.sh) $ echo $test 0 Any idea if this is a bug or an expected behavior ?
I tried several combinations as tested above. Using a lot of bash functions I don't see myself removing the shebang to use $BASH_SUBSHELL.