Bash "not": inverting the exit status of a command Bash "not": inverting the exit status of a command bash bash

Bash "not": inverting the exit status of a command


if ! diff -q "$f1" "$f2"; then ...


If you want to negate, you are looking for ! :

if ! diff -q $f1 $f2; then    echo "they're different"else    echo "they're the same"fi

or (simplty reverse the if/else actions) :

if diff -q $f1 $f2; then    echo "they're the same"else    echo "they're different"fi

Or also, try doing this using cmp :

if cmp &>/dev/null $f1 $f2; then    echo "$f1 $f2 are the same"else    echo >&2 "$f1 $f2 are NOT the same"fi


To negate use if ! diff -q $f1 $f2;. Documented in man test:

! EXPRESSION      EXPRESSION is false

Not quite sure why you need the negation, as you handle both cases... If you only need to handle the case where they don't match:

diff -q $f1 $f2 || echo "they're different"