On 06/03/12 17:01, Geir Hauge wrote: > 2012/6/3 Davide Baldini <baldiniebald...@gmail.com>: >> Description: >> In the following test script I run an elementary coprocess to which the >> echo built-in, run in background, attaches its standard-output: >> >> #!/bin/bash >> # TEST 1 >> coproc /bin/sleep 100 >> echo >&${COPROC[1]} & >> >> The script always fails, for no apparent reason, giving the output: >> >> ./test.sh: line 4: ${COPROC[1]}: Bad file descriptor > > The coproc fds are only available in the same shell. The subshell > created with & cannot use them. > > >> I wonder if the correct syntax should be rather this one (ampersand >> moved before redirection): >> >> #!/bin/bash >> # TEST 2 >> coproc /bin/sleep 100 >> echo & >&${COPROC[1]} > > This is equivalent to > > echo & >> &${COPROC[1]} > > & ends the command, so the redirection is not applied to the echo. > > > See http://wiki.bash-hackers.org/syntax/keywords/coproc >
Thank you Geir, I really appreciated you help and the useful bash-hackers.org link. Definitely, the GNU Bash manual would need some deeper details on these niche features.