summaryrefslogtreecommitdiff
path: root/devdocs/bash/looping-constructs.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/bash/looping-constructs.html
new repository
Diffstat (limited to 'devdocs/bash/looping-constructs.html')
-rw-r--r--devdocs/bash/looping-constructs.html18
1 files changed, 18 insertions, 0 deletions
diff --git a/devdocs/bash/looping-constructs.html b/devdocs/bash/looping-constructs.html
new file mode 100644
index 00000000..9b70c86c
--- /dev/null
+++ b/devdocs/bash/looping-constructs.html
@@ -0,0 +1,18 @@
+<h1 class="subsubsection">Looping Constructs</h1> <p>Bash supports the following looping constructs. </p> <p>Note that wherever a ‘<samp>;</samp>’ appears in the description of a command’s syntax, it may be replaced with one or more newlines. </p> <dl compact> <dt id="index-until"><span><code>until</code></span></dt> <dd>
+ <p>The syntax of the <code>until</code> command is: </p> <div class="example"> <pre class="example">until test-commands; do consequent-commands; done
+</pre>
+</div> <p>Execute <var>consequent-commands</var> as long as <var>test-commands</var> has an exit status which is not zero. The return status is the exit status of the last command executed in <var>consequent-commands</var>, or zero if none was executed. </p> </dd> <dt id="index-while"><span><code>while</code></span></dt> <dd>
+<p>The syntax of the <code>while</code> command is: </p> <div class="example"> <pre class="example">while test-commands; do consequent-commands; done
+</pre>
+</div> <p>Execute <var>consequent-commands</var> as long as <var>test-commands</var> has an exit status of zero. The return status is the exit status of the last command executed in <var>consequent-commands</var>, or zero if none was executed. </p> </dd> <dt id="index-for"><span><code>for</code></span></dt> <dd>
+<p>The syntax of the <code>for</code> command is: </p> <div class="example"> <pre class="example">for name [ [in [words …] ] ; ] do commands; done
+</pre>
+</div> <p>Expand <var>words</var> (see <a href="shell-expansions">Shell Expansions</a>), and execute <var>commands</var> once for each member in the resultant list, with <var>name</var> bound to the current member. If ‘<samp>in <var>words</var></samp>’ is not present, the <code>for</code> command executes the <var>commands</var> once for each positional parameter that is set, as if ‘<samp>in "$@"</samp>’ had been specified (see <a href="special-parameters">Special Parameters</a>). </p> <p>The return status is the exit status of the last command that executes. If there are no items in the expansion of <var>words</var>, no commands are executed, and the return status is zero. </p> <p>An alternate form of the <code>for</code> command is also supported: </p> <div class="example"> <pre class="example">for (( expr1 ; expr2 ; expr3 )) ; do commands ; done
+</pre>
+</div> <p>First, the arithmetic expression <var>expr1</var> is evaluated according to the rules described below (see <a href="shell-arithmetic">Shell Arithmetic</a>). The arithmetic expression <var>expr2</var> is then evaluated repeatedly until it evaluates to zero. Each time <var>expr2</var> evaluates to a non-zero value, <var>commands</var> are executed and the arithmetic expression <var>expr3</var> is evaluated. If any expression is omitted, it behaves as if it evaluates to 1. The return value is the exit status of the last command in <var>commands</var> that is executed, or false if any of the expressions is invalid. </p>
+</dd> </dl> <p>The <code>break</code> and <code>continue</code> builtins (see <a href="bourne-shell-builtins">Bourne Shell Builtins</a>) may be used to control loop execution. </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/Looping-Constructs.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Looping-Constructs.html</a>
+ </p>
+</div>