On Wed, Jan 24, 2018 at 3:55 PM, Tadeus Prastowo <tadeus.prast...@unitn.it> wrote: > On Wed, Jan 24, 2018 at 3:53 PM, Chet Ramey <chet.ra...@case.edu> wrote: >> On 1/24/18 9:50 AM, Tadeus Prastowo wrote: >>> On Wed, Jan 24, 2018 at 3:16 PM, Chet Ramey <chet.ra...@case.edu> wrote: >>>> On 1/24/18 3:38 AM, Tadeus Prastowo wrote: >>>>> Hi! >>>>> >>>>> To quote >>>>> https://www.gnu.org/software/bash/manual/html_node/Coprocesses.html#Coprocesses >>>>> >>>>> "The file descriptors are not available in subshells." >>>> >>>> The file descriptors are set to close-on-exec, so they're not available >>>> to new processes, and closed explicitly when executing subshell commands >>>> such as ( ... ) and asynchronous commands run with `&'. Command and >>>> process substitutions are created as exact copies of their parent, and >>>> inherit the file descriptors. >>> >>> So, the documentation should be fixed, no? >> >> Sure, it can be clarified. > > Okay, I will propose a patch.
diff --git a/doc/bashref.texi b/doc/bashref.texi index c0f4a2f..fee8f0e 100644 --- a/doc/bashref.texi +++ b/doc/bashref.texi @@ -1197,7 +1197,10 @@ This pipe is established before any redirections specified by the command (@pxref{Redirections}). The file descriptors can be utilized as arguments to shell commands and redirections using standard word expansions. -The file descriptors are not available in subshells. +The file descriptors are not available in subshells other than those +created by command and process substitutions (see the descriptions +the substitutions in @ref{Command Substitution} and +@ref{Process Substitution}, respectively). The process ID of the shell spawned to execute the coprocess is available as the value of the variable @env{NAME}_PID. @@ -3025,6 +3028,12 @@ shell's parent, and traps ignored by the shell are ignored A command invoked in this separate environment cannot affect the shell's execution environment. +Command substitution and process substitution are invoked in a +separate execution environment that starts as an exact duplicate of +the execution environment of the shell. As before, any command within +the separate execution environment cannot affect the shell's execution +environment. + Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in a subshell environment that is a duplicate of the shell environment, What do you think? > Meanwhile, I observe another problem > that I will send in the next e-mail. Sorry, it is not a problem after I read your e-mail almost 7 years ago. To quote https://lists.gnu.org/archive/html/bug-bash/2011-04/msg00056.html, the man page says under BUGS: There may be only one active coprocess at a time. (The shell will forget about earlier coprocs and not mark them as completed, for instance.) End quote. By forgetting, I see that it also means that the FDs of the forgotten coproc(s) have to be closed manually by subshells that do not need the FDs and do not perform execve, such as builtin commands and shell functions (e.g., coproc pA (cat); coproc pB (cat); echo xxx | read myinput; will cause the subshells in the pipe to inherit the FDs of pA but not pB). >> -- >> ``The lyf so short, the craft so long to lerne.'' - Chaucer >> ``Ars longa, vita brevis'' - Hippocrates >> Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/ -- Best regards, Tadeus