1
2
3
4
5
6
7
8
9
10
11
12
|
<h1 class="subsection">Lists of Commands</h1> <p>A <code>list</code> is a sequence of one or more pipelines separated by one of the operators ‘<samp>;</samp>’, ‘<samp>&</samp>’, ‘<samp>&&</samp>’, or ‘<samp>||</samp>’, and optionally terminated by one of ‘<samp>;</samp>’, ‘<samp>&</samp>’, or a <code>newline</code>. </p> <p>Of these list operators, ‘<samp>&&</samp>’ and ‘<samp>||</samp>’ have equal precedence, followed by ‘<samp>;</samp>’ and ‘<samp>&</samp>’, which have equal precedence. </p> <p>A sequence of one or more newlines may appear in a <code>list</code> to delimit commands, equivalent to a semicolon. </p> <p>If a command is terminated by the control operator ‘<samp>&</samp>’, the shell executes the command asynchronously in a subshell. This is known as executing the command in the <em>background</em>, and these are referred to as <em>asynchronous</em> commands. The shell does not wait for the command to finish, and the return status is 0 (true). When job control is not active (see <a href="job-control">Job Control</a>), the standard input for asynchronous commands, in the absence of any explicit redirections, is redirected from <code>/dev/null</code>. </p> <p>Commands separated by a ‘<samp>;</samp>’ are executed sequentially; the shell waits for each command to terminate in turn. The return status is the exit status of the last command executed. </p> <p><small>AND</small> and <small>OR</small> lists are sequences of one or more pipelines separated by the control operators ‘<samp>&&</samp>’ and ‘<samp>||</samp>’, respectively. <small>AND</small> and <small>OR</small> lists are executed with left associativity. </p> <p>An <small>AND</small> list has the form </p>
<div class="example"> <pre class="example">command1 && command2
</pre>
</div> <p><var>command2</var> is executed if, and only if, <var>command1</var> returns an exit status of zero (success). </p> <p>An <small>OR</small> list has the form </p>
<div class="example"> <pre class="example">command1 || command2
</pre>
</div> <p><var>command2</var> is executed if, and only if, <var>command1</var> returns a non-zero exit status. </p> <p>The return status of <small>AND</small> and <small>OR</small> lists is the exit status of the last command executed in the list. </p><div class="_attribution">
<p class="_attribution-p">
Copyright © 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/Lists.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Lists.html</a>
</p>
</div>
|