[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Redirect a backgrounded process' stdout toward COPROC's stdin
From: |
Geir Hauge |
Subject: |
Re: Redirect a backgrounded process' stdout toward COPROC's stdin |
Date: |
Sun, 3 Jun 2012 17:01:29 +0200 |
2012/6/3 Davide Baldini <baldiniebaldini@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