#!/bin/bash # # Syntax: mgrep [-w] [-u] [-o] [-h] string # # Purpose: Searches all .m files in the directories ~/matlab for # the given string. # If the option -w is specified, mgrep searches for string as a # word. # If the option -u is specified, mgrep distinguishes between upper # and lower case letters. # If the option -o is specified, 'old' and 'bak' subdirectories are # also searched. # The -h flag shows the help info for this command. # Created: Oct 20, 1993 by Bart De Schutter # Last revised: Jan 2, 2011 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: matlab word_option="" case_option="-i" old_dirs=0 while getopts :wuoh option do case "$option" in w) word_option="-w";; u) case_option="";; o) old_dirs=1;; 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 if [ $old_dirs -eq 0 ]; then find_options='! -path "*/old/*" ! -path "*/bak/*"' else find_options="" fi cd ~/matlab find . ! -path '*mdata*' \ $find_options \ -name "*.m" \ -exec findgrepsub $case_option $word_option "$1" {} \; #eval "find . ! -path '*mdata*' \ # $find_options \ # -name \"*.m\" \ # -exec findgrepsub $tmp_file $grep_options "$1" {} \;"