#!/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"). # (Short version; uses a 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 for file do # Make sure they are files, not directories. # Make sure they are readable. # Make sure they are not executable. # Make sure they aren't empty. # if [ ! -f "$file" ]; then echo 1>&2 "$0: '$file' is not a file" exit 1 fi if [ ! -r "$file" ]; then echo 1>&2 "$0: '$file' is not a readable file" exit 1 fi if [ -x "$file" ]; then echo 1>&2 "$0: '$file' is executable" exit 1 fi if [ ! -s "$file" ]; then echo 1>&2 "$0: '$file' is empty" exit 1 fi done # 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