#!/bin/sh -u # This scripts sorts a file and displays the top 5 lines. #------------------------------------------------------------ # Syntax: # $0 filename #------------------------------------------------------------ # Purpose: # Validate the filename, sort it, and display the top 5 lines. #------------------------------------------------------------- # Student Name: Ian! D. Allen # Algonquin EMail Address: alleni # Student Number: 000-000-000 # Course Number: DAT2330 # Lab Section Number: 010 # Professor Name: Ian! D. Allen # Assignment Name/Number/Date: Sample Winter 2003 # Comment: This is a sample assignment label. # see http://idallen.com/teaching/assignment_standards.html #------------------------------------------------------------- # Set standard search path and umask. # PATH=/bin:/usr/bin ; export PATH umask 022 # Make sure we have exactly one command line argument. # If not, echo the count and incorrect input back to the user on stderr. # if [ $# -ne 1 ] ; then echo 1>&2 "$0: Expecting one argument, found $# (${*-})" exit 1 fi # Echo the user's input argument back to the user before validating it. # echo "You entered: '$1'" # Validate: Make sure the filename is a file, readable, non-zero size. # if [ ! -f "$1" ] ; then echo 1>&2 "$0: '$1' is not a file." exit 1 fi if [ ! -r "$1" ] ; then echo 1>&2 "$0: '$1' is not readable." exit 1 fi if [ ! -s "$1" ] ; then echo 1>&2 "$0: '$1' is empty." exit 1 fi # This is the actual work of the script. # Sort the file first, then extract the top 5 lines. # sort "$1" | head -5 # The script exits with exit status of last command executed.