#!/bin/sh -u # $0 pathname # Tells whether a pathname is a file or directory. # Lists the contents of a directory; word counts a file. # -IAN! idallen@ncf.ca June 2001 export PATH=/bin:/usr/bin umask 022 # Make sure we have exactly one argument to this script. # if [ $# -ne 1 ]; then echo 1>&2 "$0: Expecting exactly one argument; found $#" exit 1 fi # Test to see if the pathname is a directory. # List the contents and then exit, if it is. # if [ -d "$1" ]; then echo "'$1' is a directory" ls "$1" || exit $? exit 0 fi # Test to see if the pathname is a file. # Get a word count of lines and then exit, if it is. # if [ -f "$1" ]; then echo "'$1' is a file" lines=$(wc -l <"$1") || exit $? echo "It contains $lines lines" exit 0 fi # Argument is not a file or directory - print an error message. # Exit with some non-zero return status. # echo 1>&2 "$0: '$1' is not a file or directory" exit 3