#!/bin/sh -u # $0 [ filenames... ] # Show how each file name differs from its sorted version. # -IAN! idallen@ncf.ca export PATH=/bin:/usr/bin umask 022 # Loop for each command line argument. # for file do echo "Processing: $file" # Validate the arguments. # if [ ! -r "$file" ]; then echo 1>&2 "$0: '$file' is not readable" exit 1 fi if [ ! -f "$file" ]; then echo 1>&2 "$0: '$file' is not a file" exit 1 fi # Sort the file into a temporary file. # Count the differences (remove the leading blanks from the number). # Print the message. # sorted=/tmp/sorted$$ sort "$file" >"$sorted" || exit $? count=$(diff "$file" "$sorted" | wc -l | tr -d " ") echo "The file differs from its sorted version by $count lines." rm "$sorted" done