bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: errexit is not suspended in a pipeline


From: Quinn Grier
Subject: Re: errexit is not suspended in a pipeline
Date: Wed, 11 Jan 2023 13:04:51 -0800
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1

On 2023-01-11 06:44, Chet Ramey wrote:
On 1/10/23 9:36 PM, Quinn Grier wrote:
In the documentation for set -e, the Bash manual says that errexit is
suspended in all but the last command of a pipeline:

        The shell does not exit if the command that fails is part of
        [...] any command in a pipeline but the last

I'm not sure why you included the `part of' in your quote, since it clearly
applies to the text following it: "part of the command list immediately
following as while or until keyword, part of the test following ..."

I agree, my quotation of that documentation is wrong, as "part of" does
not apply to "any command in a pipeline". However, I still think my
example script shows something fishy.

Here's another example script that might help show what I mean. This one
goes through all of the apparent contexts where set -e is ignored:

      # Without set -e, all "echo" commands run.
      while (false; echo -n 1); do break; done # Outputs 1
      until (false; echo -n 2); do break; done # Outputs 2
      if (false; echo -n 3); then :; fi        # Outputs 3
      (false; echo -n 4) && :                  # Outputs 4
      (false; echo -n 5) || :                  # Outputs 5
      (false; echo -n 6) | cat                 # Outputs 6
      ! (false; echo -n 7)                     # Outputs 7
      echo

      # With set -e, all "echo" commands should still run despite
      # the fact that "false" would normally cause an exit before
      # "echo", as these are all contexts where set -e is ignored.
      set -e
      while (false; echo -n 1); do break; done # Outputs 1
      until (false; echo -n 2); do break; done # Outputs 2
      if (false; echo -n 3); then :; fi        # Outputs 3
      (false; echo -n 4) && :                  # Outputs 4
      (false; echo -n 5) || :                  # Outputs 5
      (false; echo -n 6) | cat                 # No output (!)
      ! (false; echo -n 7)                     # Outputs 7
      echo

The output of this script is:

      1234567
      123457

Why is "6" missing from the second line?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]