: ########################################################################## # Shellscript: rgrep - recursive grep # Version : 0.1 (beta) # Author : Heiner Steven (heiner.steven@odn.de) # Date : 12.02.1996 # Category : File Utilities # SCCS-Id. : $Id: rgrep,v 1.1.1.1 1999/06/15 19:29:05 heiner Exp $ ########################################################################## # Description # ########################################################################## PN=`basename $0` # Program name VER='0.1 (beta)' : ${GREP:=egrep} FindOpts="-follow -type f" GrepOpts= Usage () { echo >&2 "$PN - recursive grep, $VER (hs '96) usage: $PN [grep_opts | find_opts] SearchString [file | directory] ... grep_opts: Options for $GREP (the default is \"$GrepOpts\") find_opts: Options for find (the default is \"$FindOpts\"). Options consisting of a single letter are considered to be $GREP options, longer options are interpreted as find options. Options with arguments must be quoted: \"-type d\" instead -type d" exit 1 } Msg () { for i do echo "$PN: $i" >&2 done } Fatal () { Msg "$@"; exit 1; } Args= while [ $# -gt 0 ] do case "$1" in --) shift; break;; -h) Usage;; -?) GrepOpts="${GrepOpts:+$GrepOpts }$1";; -??*) Args="${Args:+$Args }$1";; *) break;; # First file name esac shift done [ -n "$Args" ] && FindOpts="$Args" [ $# -lt 1 ] && Usage Search="$1"; shift [ $# -lt 1 ] && set -- . # Default search directory exec find "$@" $FindOpts -print | xargs $GREP $GrepOpts "$Search" /dev/null