coproc
Bash builtin for creating interactive asynchronous subshells. tldr-pages
On several platforms
Several platforms
Run a subshell asynchronously
coproc { command1; command2; ...; }IdentifyCreate a coprocess with a specific name
coproc name { command1; command2; ...; }IdentifyWrite to a specific coprocess stdin
echo "input" >&"${name[1]}"IdentifyRead from a specific coprocess stdout
read <&"${name[0]}" variableIdentifyCreate a coprocess which repeatedly reads stdin and runs some commands on the input
coproc name { while read line; do command1; command2; ...; done }IdentifyCreate a coprocess which repeatedly reads stdin, runs a pipeline on the input, and writes the output to stdout
coproc name { while read line; do echo "$line" | command1 | command2 | ... | cat /dev/fd/0; done }IdentifyCreate and use a coprocess running bc
coproc BC { bc --mathlib; }; echo "1/3" >&"${BC[1]}"; read <&"${BC[0]}" output; echo "$output"Identify