Forrest logo
back to the coproc tool

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

The given command is using a bash feature called "coprocess".

The syntax coproc ${name} { ... } creates a coprocess with the given name. A coprocess is a way to execute a command or a block of code in parallel with the script. In this case, ${name} is the name of the coprocess.

Inside the block { ... }, there is a while loop that reads input line by line. Each line is stored in the variable line.

Within the loop, there is another block of code denoted by ${command1; command2; ---}. This block represents a series of commands that are being executed for each input line. You would replace command1, command2, etc., with the actual commands you want to run.

So, this command sets up a coprocess named ${name} that continuously reads input from a source and executes a series of commands for each line of input.

This explanation was created by an AI. In most cases those are correct. But please always be careful and never run a command you are not sure if it is safe.
back to the coproc tool