Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
added 314 characters in body
Source Link
ilkkachu
  • 148k
  • 16
  • 268
  • 441

The exclamation point just logically reverses the return code of the command/pipeline (see e.g. Bash's manual):

if true ;    then echo 'this prints' ; fi
if ! false ; then echo 'this also prints' ; fi
if ! true ;  then echo 'this does not print' ; fi

The return code of a pipeline is (usually) just the return code of the last command, so the bang inverts that:

if ! true | false ; then echo 'again, this also prints' ; fi

As it happens, I can't see that BNF file in the Bash source distribution, and the quoted grammar isn't exactly accurate, as Bash does accept multiple bangs since Bash 4.2 (released in 2011):

if ! ! true ; then echo 'this prints too' ; fi

That's not standard, though, and e.g. zsh and Dash croak at it.

The exclamation point just logically reverses the return code of the command/pipeline (see e.g. Bash's manual):

if true ;    then echo 'this prints' ; fi
if ! false ; then echo 'this also prints' ; fi
if ! true ;  then echo 'this does not print' ; fi

The return code of a pipeline is (usually) just the return code of the last command, so the bang inverts that:

if ! true | false ; then echo 'again, this also prints' ; fi

The exclamation point just logically reverses the return code of the command/pipeline (see e.g. Bash's manual):

if true ;    then echo 'this prints' ; fi
if ! false ; then echo 'this also prints' ; fi
if ! true ;  then echo 'this does not print' ; fi

The return code of a pipeline is (usually) just the return code of the last command, so the bang inverts that:

if ! true | false ; then echo 'again, this also prints' ; fi

As it happens, I can't see that BNF file in the Bash source distribution, and the quoted grammar isn't exactly accurate, as Bash does accept multiple bangs since Bash 4.2 (released in 2011):

if ! ! true ; then echo 'this prints too' ; fi

That's not standard, though, and e.g. zsh and Dash croak at it.

The exclamation point just logically reverses the return code of the command/pipeline (see e.g. Bash's manual):

if true ;    then echo this'this printsprints' ; fi
if ! false ; then echo this'this also printsprints' ; fi
if ! true ;  then echo this'this does not printprint' ; fi

The return code of a pipeline is (usually) just the return code of the last command, so the bang inverts that:

if ! true | false ; then echo again'again, this also printsprints' ; fi

The exclamation point just logically reverses the return code of the command/pipeline (see e.g. Bash's manual):

if true ;    then echo this prints ; fi
if ! false ; then echo this also prints ; fi
if ! true ;  then echo this does not print ; fi

The return code of a pipeline is (usually) just the return code of the last command, so the bang inverts that:

if ! true | false ; then echo again, this also prints ; fi

The exclamation point just logically reverses the return code of the command/pipeline (see e.g. Bash's manual):

if true ;    then echo 'this prints' ; fi
if ! false ; then echo 'this also prints' ; fi
if ! true ;  then echo 'this does not print' ; fi

The return code of a pipeline is (usually) just the return code of the last command, so the bang inverts that:

if ! true | false ; then echo 'again, this also prints' ; fi
Source Link
ilkkachu
  • 148k
  • 16
  • 268
  • 441

The exclamation point just logically reverses the return code of the command/pipeline (see e.g. Bash's manual):

if true ;    then echo this prints ; fi
if ! false ; then echo this also prints ; fi
if ! true ;  then echo this does not print ; fi

The return code of a pipeline is (usually) just the return code of the last command, so the bang inverts that:

if ! true | false ; then echo again, this also prints ; fi