How to get the opposite if construct in Bash?

if date -d "2012010123"executed if the date command returns a null exit code. How do I get the opposite? In other words, how can I get an if statement to run if the exit code is 1?

+3
source share
1 answer

Cancel it:

if ! date -d "2012010123"; then
  # do something here (date returned with non-zero exit code)
fi

Quote from help test:

  ! EXPR         True if expr is false.
+7
source

All Articles