Read and write to a co-process in bash
Hello all,
Ksh provides the option to read from a co-process by means of: Code:
#!/bin/ksh Using a pipeline is no option for me as I set some shell variables inside the while loop that I need to access later on. Thanks, Opher. |
It depends. The evident way is to use a file to hold the data, and read it back from the loop.
You can take the whole list into the loop with <<<, like this Code:
IFS=' ' |
Thanks for the reply,
Quote:
Also, I'm not sure how this behaves if I background (&) the first command and in my script read faster than the command generates output ...? Quote:
Code:
{ |
Some more research (google -> bash FAQ) revealed that co-processes are not supported directly.
Instead, one can use a named pipe pair (one for input and one for output). There are two options: 1) place the extra code in your script. 2) source the functions/coproc.bash (from the 3.2 distribution) ex. Code:
local fifo="/var/tmp/getoptions.$$.$RANDOM" |
All times are GMT -5. The time now is 06:14 PM. |