[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Redirect a backgrounded process' stdout toward COPROC's stdin
From: |
Davide Baldini |
Subject: |
Re: Redirect a backgrounded process' stdout toward COPROC's stdin |
Date: |
Sun, 03 Jun 2012 18:22:28 +0200 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.16) Gecko/20111110 Icedove/3.0.11 |
On 06/03/12 17:01, Geir Hauge wrote:
> 2012/6/3 Davide Baldini <address@hidden>:
>> 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.