How to invert command exit code?
1 answer
+4
−0
An exclamation mark followed by a space in the beginning of a pipeline will negate the final exit code of the pipeline.
Here's an example in Bash. Echoing $?
will print out the exit code of the previous command (which is also an echo in this case).
$ echo OpenStreetMap is the best map
OpenStreetMap is the best map
$ echo $?
0
$ ! echo OpenStreetMap is meh
OpenStreetMap is meh
$ echo $?
1
This is a Posix thing.
0 comment threads