linux - source - the dot shell command

What's the meaning of a ! before a command in the shell? (2)

"!" Means "not", so when you place it before a command and you run "$?" It will echo a 1. Which means it failed instead of a 0, which means success.

The question is in the title. What is the purpose of a shell command (part of a shell script) starting with an exclamation mark? Concrete example:


#!/usr/bin/env bash
set -e
! docker stop foo
! docker rm -f foo
# ... other stuff

I know that without the space the exclamation mark is used for history replacements and ! <expression> according to the man page can be used to evaluate " True if expr is false ". But in the example context that does not make sense to me.

If you don't want the script to fail in both cases, error or success of the command, you can also use this alternative:

set -e
docker stop foo || true

The boolean or true makes the pipeline always have 0 as the return value.