[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
coproc FDs (file descriptors) available to subshells
From: |
Tadeus Prastowo |
Subject: |
coproc FDs (file descriptors) available to subshells |
Date: |
Wed, 24 Jan 2018 09:38:53 +0100 |
Hi!
To quote
https://www.gnu.org/software/bash/manual/html_node/Coprocesses.html#Coprocesses
"The file descriptors are not available in subshells."
So, that is my expectation. However, the following Bash fails me:
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-unknown-linux-gnu'
-DCONF_VENDOR='unknown' -DLOCALEDIR='/usr/local/share/locale'
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include
-I./lib -g -O2 -Wno-parentheses -Wno-format-security
uname output: Linux 0x657573 4.4.0-111-generic #134-Ubuntu SMP Mon Jan
15 14:53:09 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-unknown-linux-gnu
Bash Version: 4.4
Patch Level: 12
Release Status: release
Description:
First, to quote
https://www.gnu.org/software/bash/manual/html_node/Command-Substitution.html#Command-Substitution
"Bash performs the expansion by executing command in a subshell environment"
However, the following works: coproc cat >/tmp/test.txt; echo x $(echo
hello777 >&${COPROC[1]}) y; exec {COPROC[1]}<&- ; cat /tmp/test.txt
Specifically, I use command substitution to feed the coproc with
hello777. And, the coproc receives that string storing it in
/tmp/test.txt. But, command substitution creates a subshell. So,
coproc file descriptors are available in subshells, contradicting
coproc documentation.
Second, to quote
https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html#Process-Substitution
"The process list is run asynchronously"
However, the following works: coproc cat >/tmp/test.txt; cat <(echo
hello888 >&${COPROC[1]}); exec {COPROC[1]}<&- ; cat /tmp/test.txt
Specifically, I use process substitution to feed the coproc with
hello888. And, the coproc receives that string storing it in
/tmp/test.txt. But, process substitution creates a subshell because
it runs asynchronously. So, coproc file descriptors are available in
subshells, contradicting coproc documentation.
How should the contradiction be resolved?
Thank you.
--
Best regards,
Tadeus
- coproc FDs (file descriptors) available to subshells,
Tadeus Prastowo <=
- Re: coproc FDs (file descriptors) available to subshells, Chet Ramey, 2018/01/24
- Re: coproc FDs (file descriptors) available to subshells, Tadeus Prastowo, 2018/01/24
- Re: coproc FDs (file descriptors) available to subshells, Chet Ramey, 2018/01/24
- Message not available
- Re: coproc FDs (file descriptors) available to subshells, Tadeus Prastowo, 2018/01/24
- Re: coproc FDs (file descriptors) available to subshells, Tadeus Prastowo, 2018/01/24
- Re: coproc FDs (file descriptors) available to subshells, Tadeus Prastowo, 2018/01/24
- Fwd: coproc FDs (file descriptors) available to subshells, Tadeus Prastowo, 2018/01/26
- Message not available
- Re: Fwd: coproc FDs (file descriptors) available to subshells, Tadeus Prastowo, 2018/01/26