"One of the new features in bash 4.0 is the coproc statement.
The coproc statement allows you to create a co-process that is
connected to the invoking shell via two pipes: one to send input to
the co-process and one to get output from the co-process.
"The first use that I found for this I discovered while trying
to do logging and using exec redirections. The goal was to allow
you to optionally start writing all of a script's output to a log
file once the script had already begun (e.g. due to a --log command
"The main problem with logging output after the script has
already started is that the script may have been invoked with the
output already redirected (to a file or to a pipe). If we change
where the output goes when the output has already been redirected
then we will not be executing the command as intended by the
Some of the products that appear on this site are from companies from which QuinStreet receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. QuinStreet does not include all companies or all types of products available in the marketplace.