LinuxCommandLibrary

coproc

Bash builtin for creating interactive asynchronous subshells.

TLDR

Run a subshell asynchronously

$ coproc { [command1; command2; ...]; }
copy


Create a coprocess with a specific name
$ coproc [name] { [command1; command2; ...]; }
copy


Write to a specific coprocess stdin
$ echo "[input]" >&"$[{name][1]}"
copy


Read from a specific coprocess stdout
$ read [variable] <&"$[{name][0]}"
copy


Create a coprocess which repeatedly reads stdin and runs some commands on the input
$ coproc [name] { while read line; do [command1; command2; ...]; done }
copy


Create and use a coprocess running bc
$ coproc BC { bc --mathlib; }; echo "1/3" >&"${BC[1]}"; read output <&"${BC[0]}"; echo "$output"
copy

Help


Copied to clipboard