mirror of
https://github.com/tldr-pages/tldr.git
synced 2025-07-27 19:15:27 +02:00

* Update rpicam-still.md * Update jello.md * Update dropdb.md * Update aws-eks.md * Update sfdisk.md * Update hyperfine.md * Update quarto.md * Update for.md * Update coproc.md * Update vagrant-validate.md * Update kubetail.md * Update kubetail.md * Update pstoedit.md * Update highlight.md * Update linode-cli-linodes.md * Update swig.md * Update phpcbf.md * Update unzipsfx.md * Update d8.md * Update trdsql.md * Update keyd.md * Update mamba-repoquery.md * Update pages/common/jello.md * Update coproc.md * Apply suggestions from code review Co-authored-by: Lena <126529524+acuteenvy@users.noreply.github.com> * Update pages/common/for.md Co-authored-by: Lena <126529524+acuteenvy@users.noreply.github.com> * Update for.md --------- Co-authored-by: Lena <126529524+acuteenvy@users.noreply.github.com>
32 lines
1 KiB
Markdown
32 lines
1 KiB
Markdown
# 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 { {{command1; command2; ...}}; }`
|
|
|
|
- Create a coprocess with a specific name:
|
|
|
|
`coproc {{name}} { {{command1; command2; ...}}; }`
|
|
|
|
- Write to a specific coprocess `stdin`:
|
|
|
|
`echo "{{input}}" >&"${{{name[1]}}}"`
|
|
|
|
- Read from a specific coprocess `stdout`:
|
|
|
|
`read {{variable}} <&"${{{name[0]}}}"`
|
|
|
|
- Create a coprocess which repeatedly reads `stdin` and runs some commands on the input:
|
|
|
|
`coproc {{name}} { while read line; do {{command1; command2; ...}}; done }`
|
|
|
|
- Create 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 }`
|
|
|
|
- Create and use a coprocess running `bc`:
|
|
|
|
`coproc BC { bc --mathlib; }; echo "1/3" >&"${BC[1]}"; read output <&"${BC[0]}"; echo "$output"`
|