#!/bin/csh # Easy word counting shell script # Execute wc command and put output into an array variable # If command succeeded then report results in plain english # Otherwise print error message set prog = "`basename $0`:" if ($#argv == 0) then echo "$prog at least one filename argument is required" exit 1 endif foreach filename ( $argv[*] ) if 1 - (-e $filename) then echo "$prog file $filename does not exist" goto do_rest endif if 1 - (-r $filename) then echo "$prog cannot read file $filename" goto do_rest endif if -d $filename then echo "$prog file $filename is a directory" goto do_rest endif set wco = `wc $filename` if ($status == 0) then echo "File $filename contains $wco[1] lines, $wco[2] words and $wco[3] chars" else echo "$prog file $filename could not be processed." endif do_rest: end