Subject: bug#62406: “! failing-command” pattern in shell tests is wrong

From: Martin Castillo <[email-masked]>
Date: Sun, 26 Mar 2023 20:16:38 +0200

Hi,

Am 23.03.23 um 17:00 schrieb Ludovic Courtès:> In 
<https://issues.guix.gnu.org/43616> (commit
 > d8934360d2453a403b5433e71d09188e4ed23b57), we changed:
 >
 >    if command that should fail; then false; else true; fi
 >
 > to:
 >
 >    ! command that should fail
 >
 > I had reservations back then, and now I know why: :-)
 >
 > --8<---------------cut here---------------start------------->8---
 > $ bash -xe -c '! true; true'
 > + true
 > + true
 > $ echo $?
 > 0
 > $ bash -xe -c '! false; true'
 > + false
 > + true
 > $ echo $?
 > 0
 > --8<---------------cut here---------------end--------------->8---
 >
 > Whether or not the command following the exclamation mark succeeds, the
 > statement succeeds.  Bummer.
 >
 > The Bash manual (info "(bash) Pipelines") reads:
 >
 >    If the reserved word '!' precedes the pipeline, the exit status is the
 >    logical negation of the exit status as described above.  The shell
 >    waits for all commands in the pipeline to terminate before returning a
 >    value.
 >
 > To me, that means it should work as we thought, but it’s a fact that it
 > doesn’t.
the documentation on `-e` says:

-e      Exit  immediately  if a pipeline (which may consist of a
         single simple command), a list, or  a  compound  command
         (see SHELL GRAMMAR above), exits with a non-zero status.
         The shell does not exit [...] if the
         command's return value is being inverted with !.

I have no idea what might be the rationale for that.