#!/bin/sh -u # $0 [ filename ] # Concatenate the given file name over and over into another file. # Prompt for a file name if there are no command line arguments. # -IAN! idallen@ncf.ca export PATH=/bin:/usr/bin umask 022 # The name of our output file. # outputfile="bar" # Validate the correct number of arguments on the command line. # if [ "$#" -ge 2 ] ; then echo 1>&2 "$0: Expecting zero or one argument, found $# ($*)" exit 1 # return a bad exit code fi # If there are no arguments, get one from standard input. # Echo the name being processed back to the user. # if [ "$#" -eq 0 ] ; then echo 1>&2 "Please enter a file name:" read filename else filename="$1" fi echo "I am processing '$filename'." # Verify that the user's input is 1) a file, 2) readable, 3) not empty. # if [ ! -f "$filename" ]; then echo 1>&2 "$0: '$filename' is not a file" exit 1 # return a bad exit code fi if [ ! -r "$filename" ]; then echo 1>&2 "$0: '$filename' is not readable" exit 1 # return a bad exit code fi if [ ! -s "$filename" ]; then echo 1>&2 "$0: '$filename' has no size (is empty)" exit 1 # return a bad exit code fi # Empty the output file. # Loop, appending, while the number of lines is less than the constant. # We *must* use the syntax <"$outputfile" to redirect stdin to "wc". # >"$outputfile" while [ $(wc -l <"$outputfile") -lt 100 ]; do linecount=$(wc -l <"$outputfile") echo "The number of lines in $outputfile is $linecount" cat "$filename" >>"$outputfile" || exit $? # exit if cat has an error done