Forrest logo
tool overview
On this page you find all important commands for the CLI tool coproc. If the command you are looking for is missing please ask our AI.

coproc

The "coproc" command line tool is a built-in command in various Unix-like operating systems, including Bash. It stands for "co-process" and is used to create a two-way communication between a Bash script and a background command. When using the "coproc" command, you can specify a command or a block of commands to run in the background while also creating two special file descriptors for communication: COPROC[0] and COPROC[1]. COPROC[0] is used for reading the output of the background command, while COPROC[1] is used for writing input to it. Here is a basic example of how to use "coproc" in a Bash script: ```bash

!/bin/bash coproc some_command # Run "some_command" in the background and create communication channels # Read the output of the command

while read -r line <&"${COPROC[0]}"; do echo "Output: $line" done # Send input to the command echo "Some input" >&"${COPROC[1]}" # Close the communication channels exec {COPROC[0]}<&- {COPROC[1]}>&-

List of commands for coproc:

  • coproc:tldr:0e9c5 coproc: Create a coprocess which repeatedly reads `stdin`, runs a pipeline on the input, and writes the output to `stdout`.
    $ coproc ${name} {select} | cat /dev/fd/0; done }
    try on your machine
    explain this command
  • coproc:tldr:512d8 coproc: Run a subshell asynchronously.
    $ coproc { ${command1; command2; ---}; }
    try on your machine
    explain this command
  • coproc:tldr:938c8 coproc: Create a coprocess which repeatedly reads `stdin` and runs some commands on the input.
    $ coproc ${name} { while read line; do ${command1; command2; ---}; done }
    try on your machine
    explain this command
  • coproc:tldr:d3ee2 coproc: Create and use a coprocess running `bc`.
    $ coproc BC { bc --mathlib; }; echo "1/3" >&"${BC[1]}"; read output <&"${BC[0]}"; echo "$output"
    try on your machine
    explain this command
  • coproc:tldr:de3e5 coproc: Create a coprocess with a specific name.
    $ coproc ${name} { ${command1; command2; ---}; }
    try on your machine
    explain this command
tool overview