coproc
Bash builtin for creating interactive asynchronous subshells. More information: https://www.gnu.org/software/bash/manual/bash.html#Coprocesses.
- Run a subshell asynchronously:
coproc { ; }
- Create a coprocess with a specific name:
coproc { ; }
- Write to a specific coprocess
stdin:
echo "" >&"$}"
- Read from a specific coprocess
stdout:
read <&"$}"
- Create a coprocess which repeatedly reads
stdinand runs some commands on the input:
coproc { while read ; do ; done }
- Create a coprocess which repeatedly reads
stdin, runs a pipeline on the input, and writes the output tostdout:
coproc { while read ; do | | cat /dev/fd/0; done }
- Create and use a coprocess running
bc:
coproc BC { bc ; }; echo "1/3" >&"${BC[1]}"; read <&"${BC[0]}" output; echo "$output"
来源:tldr-pages contributors · 作者与贡献记录 · CC BY 4.0。离线整理了版式、链接和媒体显示。
