#!/bin/sh -u # Count the number of lines in the first file name argument. # Reference: Chapter 11 # Print an error if the argument is missing, or is not a file. # -IAN! idallen@ncf.ca # Make sure we have one argument. # if [ $# -eq 1 ] ; then path="$1" echo "You are using pathname '$path'." if [ -f "$path" ] ; then echo "The path '$path' is a plain file" # this uses command substitution to get the line count lines=$( wc -l <"$path" ) echo "File '$path' contains $lines lines." else echo 1>&2 "$0: The path '$path' is missing or is not a file" fi else # Wrong number of arguments. Issue an error message. # if [ $# -eq 0 ] ; then echo 1>&2 "$0: expecting exactly one argument - none found" else echo 1>&2 "$0: expecting exactly one argument, found $# ($*)" fi fi