From the bash manual
Process substitution is supported on systems that support named pipes (fifos) or the
/dev/fd
method of naming open files. It takes the form of<(list)
or
>(list)
The process list is run with its input or output connected to a fifo or some file in
/dev/fd
. The name of this file is passed as an argument to the current command as the result of the expansion.
Is the command list
in a process substitution <(list)
or >(list)
invoked in a subshell, similarly to a command substitution, commands grouped with parentheses, and
asynchronous commands? Similar as the bash manual says
Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in a subshell environment that is a duplicate of the shell environment, except that traps caught by the shell are reset to the values that the shell inherited from its parent at invocation.
The answer might be yes, because
process substitution looks similar to command substitution,
some source says that
the command inside it is run in the background.
and the above second quote from the bash manual says that both command substitution and backgrounded commands are invoked in subshells.
The answer might be no, because
In the bash manual, I didn't see that a process substitution is mentioned in the above second quote from the bash manual,
and some source says that process substitution
is especially important for bypassing subshells caused by pipelines
although I am not sure if "bypassing subshells" means not being invoked in a subshell.
a=$$; b=$(cat <(echo $$)); if [ $a -eq $b ]; then echo "NOT in a subshell"; else echo "in a subshell"; fi
. The output was:NOT in a subshell
– Harry Jun 16 '18 at 10:18$$
get evaluated by the top-level shell. – Tom Anderson Oct 29 '18 at 17:50pstree -p $$
,echo $(pstree -p $$)
,(pstree -p $$)
, and(echo $(pstree -p $$))
- on my machine, only the process substitution inside the subshell actually spawns another subshell. – Tom Anderson Oct 29 '18 at 17:53