Example: Testing the Sort Program

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

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

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