Hi, when BASH_SUBSHELL is part of a pipeline with just a simple command it
does not increment. Consider the following:
# docker run -ti --rm bash bash -c 'echo $BASHPID $BASH_SUBSHELL; echo |
echo $BASHPID $BASH_SUBSHELL'
1 0
8 0
Doing anything else, like `echo | { echo $BASH_SUBSHELL; }` or like `f() {
echo $BASH_SUBSHELL; }; echo | f` will make it increment. The version in
docker is:
# docker run -ti --rm bash bash --version
GNU bash, version 5.2.15(1)-release (x86_64-pc-linux-musl)
The variable is not anyhow important to me and I do not care about it, just
only noticed the odd behavior when reading stackoverflow question
https://stackoverflow.com/q/76843570/9072753 question. I tried following
bash source code, but I do not know where pipeline is entering to check if
subshell_level is incremented. The release changes for bash-4.3 mention
that https://github.com/bminor/bash/blob/master/NEWS#L616 :
x. BASH_SUBSHELL is now updated for process substitution and group commands
in pipelines, and is available with the same value when running any exit
trap.
It is updated for _group commands_ specifically in pipelines. Is is this
intended behavior that for not-group commands in pipelines it is not
updated or is it rather a bug?
Thanks! Kamil Cukrowski