#!/bin/csh -f # grep_all # ----------------------------------------------------------------------------- # Shell script to grep all files in the specified directory # ----------------------------------------------------------------------------- # Usage: See Usage section below or run with -h or --help option to see usage. # Assumptions: # Effects: # Notes: # Implementation Notes: # Portability Issues: # Revision History: # $Log$ # ----------------------------------------------------------------------------- if ($#argv < 2 || "$1" == "-h" || "$1" == "--help") then echo "Usage: $0:t [options] directory grep_args... echo "Options:" echo " -v = Verbose" echo "Examples:" echo " $0:t" echo " $0:t -h" echo " $0:t --help" echo " $0:t ~/bin -i abcdef" echo " $0:t ~/bin -i -H abcdef" echo " $0:t ~/bin -i -h abcdef" echo " $0:t -v ~/bin -i -H abcdef" exit 1 endif # Collect command line options set verbose_option = "" while ($#argv > 0) if ("$1" == "-h" || "$1" == "--help") then shift # If help option was anywhere among the options, call recursively # with just that option, and exit. $0:t --help exit 1 else if ("$1" == "-v") then shift set verbose_option = "true" else # Not a recognized option. Assume it's the first parameter break endif end if ($#argv < 2) then beep "No grep args specified" $0:t --help exit 1 else if ($#argv < 1) then beep "No directory specified" $0:t --help exit 1 endif set dir_name = $1:q shift if (! -d $dir_name) then echo "$dir_name is not a directory" exit 2 endif if (`ls -1 $dir_name:q | wc -l` == 0) then echo "$dir_name is an empty directory" else if ("$verbose_option" == "true") then echo "grep $* $dir_name:q/*" endif grep $* $dir_name:q/* endif exit $status