result = $(echo 'command' <&${bkgndProc[0]})
will not work, at least basically, since it has spaces
result=$(echo 'command' <&${bkgndProc[0]})
---- Update ----
A simple concept can be shown in a script as follows:
#!/bin/bash
Outputs:
a
Another that reads multiple lines using a timeout:
#!/bin/bash coproc myproc { bash } # send a command to message 4 random numbers in 4 lines echo 'echo "$RANDOM"; echo "$RANDOM"; echo "$RANDOM"; echo "$RANDOM"' >&"${myproc[1]}" # keep reading the line until it times out while read -t 1 -u "${myproc[0]}" line; do echo "$line" done
Output:
17393 1423 8368 1782
If we use cat , it will no longer go away, since the other end is still alive and connected, and EOF has not yet been reached. This is the reason we used timeouts.
cat <&"${myproc[0]}"
source share