#!/bin/sh -u # $0 file1 file2 # Compare two non-empty files for identical content. # Display the number of lines of differences (as output by "diff"). # (Long version; no loop.) # -IAN! idallen@ncf.ca export PATH=/bin:/usr/bin umask 022 if [ $# -ne 2 ]; then echo 1>&2 "$0: Expecting 2 arguments; found $# ($*)" exit 1 fi # Make sure they are files, not directories. # if [ ! -f "$1" ]; then echo 1>&2 "$0: '$1' is not a file" exit 1 fi if [ ! -f "$2" ]; then echo 1>&2 "$0: '$2' is not a file" exit 1 fi # Make sure they are readable. # if [ ! -r "$1" ]; then echo 1>&2 "$0: '$1' is not a readable file" exit 1 fi if [ ! -r "$2" ]; then echo 1>&2 "$0: '$2' is not a readable file" exit 1 fi # Make sure they are not executable. # if [ -x "$1" ]; then echo 1>&2 "$0: '$1' is executable" exit 1 fi if [ -x "$2" ]; then echo 1>&2 "$0: '$2' is executable" exit 1 fi # Make sure they aren't empty. # if [ ! -s "$1" ]; then echo 1>&2 "$0: '$1' is empty" exit 1 fi if [ ! -s "$2" ]; then echo 1>&2 "$0: '$2' is empty" exit 1 fi # Count the differences. # Display the count if not zero. # diffs=$(diff "$1" "$2" | wc -l) if [ "$diffs" -ne 0 ]; then echo "$0: File '$1' and file '$2' are different." echo "$0: Number of lines of differences: $diffs" fi