Chet Ramey wrote: > On 4/7/11 8:06 AM, sbra...@suse.cz wrote: > > Description: > > Warning "execute_coproc: coproc [$PID:.*] still exists" as it is > > implemented makes no sense. It appears in many situations where > > it is done intentionally and it is not easy to silence it. > The warnings exist because there is really only one shell coproc > internally. You can do a lot with the arrays and shell builtins, but > as the man page says under BUGS: > > There may be only one active coprocess at a time.
Not reading this note in BUGS, I implemented an utility that uses more than one coproc to implement input dependent filtering through different commands. I wanted to save thousands of starts of the utility, so I decided to run both filters as coproc. The utility seems to work in any bash 4 version. See the end of this mail for a simplified example of my approach. > (The shell will forget about earlier coprocs and not mark them as > completed, for instance.) > > There is some support for multiple coprocs, and if there is sufficient > need, I will finish it. I'm waiting to see whether or not there is a > need for more than one simultaneous coproc -- I don't have a lot of > reports of coproc use. I consider it very useful and always wanted to have something like this in the shell. It's just a too new feature. The simplified example that demonstrates usefulness of two coproc to implement "forked pipe". If the line matches in some bash evaluation (in bash), it is sent to one filter coproc, if it is evaluated as non-matching, it is sent to another coproc. You will see the warning here, but the script itself seems to work. #!/bin/bash # Clone stdout to 3 exec 3>&1 # Run TRA filtering letter "a" coproc TRA ( sed s/a/A/g >&3 ) # Run TRB filtering letter "b" coproc TRB ( sed s/b/B/g >&3 ) while read ; do case $REPLY in /* ) echo "$REPLY" >&${TRB[1]} ;; * ) echo "$REPLY" >&${TRA[1]} ;; esac done # Close input (otherwise script will not end on EOF). eval exec ${TRA[1]}\>\&- eval exec ${TRB[1]}\>\&- # Wait to finish (otherwise script will output data after its return). wait -- Best Regards / S pozdravem, Stanislav Brabec software developer --------------------------------------------------------------------- SUSE LINUX, s. r. o. e-mail: sbra...@suse.cz Lihovarská 1060/12 tel: +49 911 7405384547 190 00 Praha 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/