Bash: using the result of a diff in a if statement Bash: using the result of a diff in a if statement bash bash

Bash: using the result of a diff in a if statement


ls -lR $dir > als -lR $dir > bDIFF=$(diff a b) if [ "$DIFF" != "" ] then    echo "The directory was modified"fi


if ! diff -q a b &>/dev/null; then  >&2 echo "different"fi


You are looking for the return value of diff and not the output of diff that you are using in your example code.

Try this:

diff a bif [ $? -ne 0 ]; then    echo "The directory was modified";fi