when using -e in bash, exclamation mark before a passing command still doesn't cause the script to fail

Viewed 161

I thought the following script would just print 'hello' and then exit with a '1'

#!/bin/bash -e

! echo hello
echo world

However, it prints

hello
world

and exits with a 0

the following script exits with a 1:

#!/bin/bash -e

! echo hello

and so does the following

#!/bin/bash -e

echo hello | grep world
! echo hello
echo world

but for some reason the -e option doesn't manage to fail the script when a command returns a failing exit code due to a ! half way through. Can anybody offer an explanation that will make me feel better about this?

1 Answers
Related