Why does $ BASH_SUBSHELL not increase in the pipe

I know that the pipe will create a subshell.

I am testing $BASH_SUBSHELL and $BASHPID , and find $BASH_SUBSHELL does not increase in the pipe

 echo $BASH_SUBSHELL # 0 echo $BASHPID # 8347 echo $BASH_SUBSHELL | cat # 0 echo $BASHPID | cat # 9727 (echo $BASH_SUBSHELL) # 1 (echo $BASHPID) # 9778 
+4
source share
1 answer

When bash simply forks, installs the command and executes it, it does not consider it to be similar.

For any control structure, for example, command commands, if and while statements, where the shell should actually be involved outside the configuration, it does this.

This can be seen from the bash source, execute_command_internal in execute_cmd.c .

+1
source

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


All Articles