#!/bin/sh -u # # $0 filename # # idallen@ncf.ca # # A script that sorts its first argument (a file name). # If the sort fails, print an error message. # The output goes to the standard output; no redirection. # # Enhance the script to make sure that only one (exactly one) # argument is supplied. Print a message if not true. # # Enhance the script to make sure that the argument is not a # directory. Print a message if not true. if test "$#" -ne 1 ; then echo "I want one argument. You gave me $#." exit 1 fi if test -d "$1" ; then echo "I want a file. You gave me a directory named '$1'." exit 1 fi if sort "$1" ; then : else echo "The sort of '$1' didn't work: status $?" fi # Another, longer way to do the above test. (Same output.) # # sort "$1" # if test $? -eq 0 ; then # : # else # echo "The sort of '$1' didn't work: status $?" # fi # The shortest way to do the above test. (Same output.) # This uses the shell's "!" return code negation operator # in front of the command to be run. # # if ! sort "$1" ; then # echo "The sort of '$1' didn't work: status $?" # fi