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 -- Geir Hauge