Example: Testing the Sort Program

#!/bin/sh
FILES=`cd input; echo *`

# Prime test data
if [ "$1" = "-p" ] ; then
        for in $FILES ; do
                sort input/$i >old/$i
        done
fi

# Compare old with new result
for in $FILES ; do
        sort input/$i >new/$i
        if diff old/$i new/$i ; then
                echo "OK $i"
        else
                echo "FAIL $i"
                exit 1
        fi
done