keyword
Bash coproc
Launch a named asynchronous coprocess with two pipe descriptors and a PID; wait for its completion. Coordinate worker lifetime.
Formal Syntax & Structure
bash syntaxbash
coproc NAME { list; }Return Value
exit status
Launch a named asynchronous coprocess with two pipe descriptors and a PID; wait for its completion. Coordinate worker lifetime.
Working Example
Example Snippetbash
coproc WORKER { IFS= read -r -t 2 request || exit 2 printf 'reply:%s\n' "$request" IFS= read -r -t 2 ack || exit 3 [[ $ack == done ]]}pid=$WORKER_PIDout=${WORKER[0]}in=${WORKER[1]}printf '%s\n' 'daily report' >&"$in"IFS= read -r -t 2 reply <&"$out" || exit 4printf '%s\n' "$reply"printf 'done\n' >&"$in"wait "$pid"printf 'worker status=%s\n' "$?"