#!/bin/sh -u # # $0 filename # # A script that sorts its first argument (it must be a file name). # If the sort fails, print an error message. # The output goes to the standard output; no redirection. # # The script verifies that there is exactly one argument and that # it is not a directory. # # WARNING: Many of the comments in this file are "Instructor-Type" # comments and are *not* appropriate for real scripts. Do not put # "Instructor-Type" comments into the scripts that you submit for marking. # I put them in my example files because I am teaching you how to # write scripts; do not submit my teaching comments back to me again. # Read the week7.txt notes for more details on good comment style. # # -IAN! idallen@ncf.ca June 2001 # all scripts must start with lines similar to these two: # export PATH=/bin:/usr/bin umask 022 # The quotes on $# aren't necessary; but, using them is good style. # # Note how the "echo" error message goes to Standard Error, and it # includes the program name and the incorrect argument count, as # well as a list of all the command line arguments. # if test "$#" -ne 1 ; then echo 1>&2 "$0: I want one argument. You gave me $# ($*)." exit 1 fi # Note how the "echo" error message goes to Standard Error, and it # includes the program name and the incorrect argument name. # # Rewrite the "test" line to use the "square bracket" form of "test". # if test -d "$1" ; then echo 1>&2 "$0: I want a file. You gave me a directory named '$1'." exit 1 fi # Note how the "echo" error message goes to Standard Error, and it # includes the program name, file name, and the error status from sort. # # If you change "exit 1" to "exit $?" will this script exit with the # bad return status of the sort command? Why not? Make it work. # if sort "$1" ; then exit 0 # it worked else echo 1>&2 "$0: The sort of '$1' didn't work: status $?" exit 1 fi