summaryrefslogtreecommitdiff
path: root/devdocs/bash/coprocesses.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/bash/coprocesses.html')
-rw-r--r--devdocs/bash/coprocesses.html14
1 files changed, 14 insertions, 0 deletions
diff --git a/devdocs/bash/coprocesses.html b/devdocs/bash/coprocesses.html
new file mode 100644
index 00000000..57417f8c
--- /dev/null
+++ b/devdocs/bash/coprocesses.html
@@ -0,0 +1,14 @@
+<h1 class="subsection">Coprocesses</h1> <p>A <code>coprocess</code> is a shell command preceded by the <code>coproc</code> reserved word. A coprocess is executed asynchronously in a subshell, as if the command had been terminated with the ‘<samp>&amp;</samp>’ control operator, with a two-way pipe established between the executing shell and the coprocess. </p> <p>The syntax for a coprocess is: </p> <div class="example"> <pre class="example">coproc [NAME] command [redirections]
+</pre>
+</div> <p>This creates a coprocess named <var>NAME</var>. <var>command</var> may be either a simple command (see <a href="simple-commands">Simple Commands</a>) or a compound command (see <a href="compound-commands">Compound Commands</a>). <var>NAME</var> is a shell variable name. If <var>NAME</var> is not supplied, the default name is <code>COPROC</code>. </p> <p>The recommended form to use for a coprocess is </p> <div class="example"> <pre class="example">coproc NAME { command; }
+</pre>
+</div> <p>This form is recommended because simple commands result in the coprocess always being named <code>COPROC</code>, and it is simpler to use and more complete than the other compound commands. </p> <p>There are other forms of coprocesses: </p> <div class="example"> <pre class="example">coproc NAME compound-command
+coproc compound-command
+coproc simple-command
+</pre>
+</div> <p>If <var>command</var> is a compound command, <var>NAME</var> is optional. The word following <code>coproc</code> determines whether that word is interpreted as a variable name: it is interpreted as <var>NAME</var> if it is not a reserved word that introduces a compound command. If <var>command</var> is a simple command, <var>NAME</var> is not allowed; this is to avoid confusion between <var>NAME</var> and the first word of the simple command. </p> <p>When the coprocess is executed, the shell creates an array variable (see <a href="arrays">Arrays</a>) named <var>NAME</var> in the context of the executing shell. The standard output of <var>command</var> is connected via a pipe to a file descriptor in the executing shell, and that file descriptor is assigned to <var>NAME</var>[0]. The standard input of <var>command</var> is connected via a pipe to a file descriptor in the executing shell, and that file descriptor is assigned to <var>NAME</var>[1]. This pipe is established before any redirections specified by the command (see <a href="redirections">Redirections</a>). The file descriptors can be utilized as arguments to shell commands and redirections using standard word expansions. Other than those created to execute command and process substitutions, the file descriptors are not available in subshells. </p> <p>The process ID of the shell spawned to execute the coprocess is available as the value of the variable <code><var>NAME</var>_PID</code>. The <code>wait</code> builtin command may be used to wait for the coprocess to terminate. </p> <p>Since the coprocess is created as an asynchronous command, the <code>coproc</code> command always returns success. The return status of a coprocess is the exit status of <var>command</var>. </p><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>Licensed under the GNU Free Documentation License.<br>
+ <a href="https://www.gnu.org/software/bash/manual/html_node/Coprocesses.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Coprocesses.html</a>
+ </p>
+</div>