coproc

Background process redirect to COPROC

喜夏-厌秋 提交于 2020-01-04 11:04:28
问题 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 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 second

More coproc questions

被刻印的时光 ゝ 提交于 2019-12-07 12:30:29
问题 This is a followup to bash coproc and leftover coproc output The idiom I finally settled on for processing a file one line at a time is: coproc cat auto/etc/build.cfg while read -u ${COPROC[0]} BRANCH TARGET SVNSRC SVNTAG BUILDTYPE DISTTYPE DISTARGS do ... commands ... done I know for the simple case of cat I could just use input redirection. This is a simplified version, where the real one uses egrep to select a subset of lines. Unfortunately this does not work. $ cat test.sh coproc cat auto

More coproc questions

谁说我不能喝 提交于 2019-12-05 13:52:20
This is a followup to bash coproc and leftover coproc output The idiom I finally settled on for processing a file one line at a time is: coproc cat auto/etc/build.cfg while read -u ${COPROC[0]} BRANCH TARGET SVNSRC SVNTAG BUILDTYPE DISTTYPE DISTARGS do ... commands ... done I know for the simple case of cat I could just use input redirection. This is a simplified version, where the real one uses egrep to select a subset of lines. Unfortunately this does not work. $ cat test.sh coproc cat auto/etc/build.cfg while read -u ${COPROC[0]} BRANCH TARGET SVNSRC SVNTAG BUILDTYPE DISTTYPE DISTARGS do

How to use 'coproc' to interact with another command driven program

余生颓废 提交于 2019-12-04 11:34:04
问题 Ok, obviously I am NOT a bash guru and am in need of one! I have never used 'coproc' before, but it seems to be just what I need. But, I have to admit that I can not extrapolate from the various 'ping' examples out there! [I did try for a couple of hours...] All I want to do is to start a 'coproc' shell script that can take input from standard in and writes it's results to standard out. I want the main script to do the sending and processing of those commands and results respectively. Here is

bash coproc and leftover coproc output

独自空忆成欢 提交于 2019-11-29 09:48:46
I need to read some configuration data into environment variables in a bash script. The "obvious" (but incorrect) pattern is: egrep "pattern" config-file.cfg | read VAR1 VAR2 VAR3 etc... This fails because the read is run in a subshell and therefore cannot set variables in the invoking shell. So I came up with this as an alternative coproc egrep "pattern" config-file.cfg read -u ${COPROC[0]} VAR1 VAR2 VAR3 etc... which works fine. To test what happens if the coprocess returns more than one line, I tried this: coproc cat config-file.cfg read -u ${COPROC[0]} VAR1 VAR2 VAR3 etc... where config

bash coproc and leftover coproc output

点点圈 提交于 2019-11-28 03:09:25
问题 I need to read some configuration data into environment variables in a bash script. The "obvious" (but incorrect) pattern is: egrep "pattern" config-file.cfg | read VAR1 VAR2 VAR3 etc... This fails because the read is run in a subshell and therefore cannot set variables in the invoking shell. So I came up with this as an alternative coproc egrep "pattern" config-file.cfg read -u ${COPROC[0]} VAR1 VAR2 VAR3 etc... which works fine. To test what happens if the coprocess returns more than one