From 0acbbfe2ca7847f8d01e36b17f7e78336d08e5c7 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Thu, 18 Nov 2021 14:27:44 +0100 Subject: [PATCH] Document that a for-loop passes through any exit status Unlike in other shells, for-loops do not set $status if 1. the loop count is zero, or if 2. the loop body consists of only commands like "set" that don't set $status. POSIX for-loops always set an exit status (they set 0 if no loop iterations). Following that would be awkward because it would add a lot of complexity in combination with the 2 special cases above. Document that "for" behaves the same as "set": it will pass through existing $status, and also the last child's $status. See the discussion in #8409 --- doc_src/cmds/for.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc_src/cmds/for.rst b/doc_src/cmds/for.rst index 3acc8e548..3e472cde4 100644 --- a/doc_src/cmds/for.rst +++ b/doc_src/cmds/for.rst @@ -15,6 +15,8 @@ Description ``for`` is a loop construct. It will perform the commands specified by ``COMMANDS`` multiple times. On each iteration, the local variable specified by ``VARNAME`` is assigned a new value from ``VALUES``. If ``VALUES`` is empty, ``COMMANDS`` will not be executed at all. The ``VARNAME`` is visible when the loop terminates and will contain the last value assigned to it. If ``VARNAME`` does not already exist it will be set in the local scope. For our purposes if the ``for`` block is inside a function there must be a local variable with the same name. If the ``for`` block is not nested inside a function then global and universal variables of the same name will be used if they exist. +Much like :ref:`set `, ``for`` does not modify $status, but the evaluation of its subordinate commands can. + Example -------