#!/bin/bash # # Syntax: findgrep [-w] [-u] [-h] string # # Purpose: Searches all files in the current directory and its subdirectories # for a given string. # If the option -w is specified, findgrep searches for string as a # word. # If the option -u is specified, findgrep distinguishes between upper # and lower case letters. # The -h flag shows the help info for this command. # Created: Nov 8, 1993 by Bart De Schutter # Last revised: Jul 31, 2007 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: files # # Process input arguments and display error message if necessary. # word_option=""; case_option="-i"; while getopts :wuh option do case "$option" in w) word_option="-w";; u) case_option="";; h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1;; esac done shift $(($OPTIND-1)) if [ $# -ne 1 ]; then echo >&2 echo >&2 "ERROR: ${0##*/} requires exactly 1 input argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi find . -type f -name "*" -exec findgrepsub $case_option $word_option "$1" {} \;