#!/bin/sh -u # $0 filename # # Verify that the script has exactly one command line argument. Verify # that the argument is a file, and that it is readable. (Print an # error message and exit the script if these things are not true.) # Sort the file and display the first five lines. # # 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 export PATH=/bin:/usr/bin umask 022 # $# is the count of arguments # -ne is a numeric comparison # $* gives all the command line arguments as one single string. # Error messages should always appear on standard error. # Exit the script with a bad (non-zero) return code upon error. # if test $# -ne 1 ; then echo 1>&2 "Expecting one argument; found $# ($*)" exit 1 fi # The "!" complements the exit code of the command: 0 to 1, 1 to 0. # The complemeted exit code is tested by the "if" statement. # if ! test -f "$1" ; then echo 1>&2 "Argument '$1' is not a file" exit 1 fi if ! test -r "$1" ; then echo 1>&2 "Argument '$1' is not readable" exit 1 fi sort "$1" | head -5