I've written a script (bgrep) for a more advanced grep command (& attached a cut down version below). I'm trying allow all grep options to be used, or in any combination.
The script works fine if I type say
bgrep -i -files product
it will return a non-case sensitive list of matches for product
however if I type
bgrep -in -files product
I get the same list & no line numbers.
I know why this is happening, it's because the -n option is a valid option for the echo command I am using. I not sure how to get round this. Is there some other command I could use.
I'd appreciate any advice, feel free to criticise.
#!/bin/sh
>grep_args
files=false
forms=false
text=""
while [ $# -gt 0 ]
do
case "$1" in
-?) echo $1 > bgrep.tmp
paste -d" " bgrep.tmp grep_args > grep_args.tmp
mv grep_args.tmp grep_args;;
-files) files=true;;
-forms) forms=true;;
-*) echo "usage :$0 [-grepoption] [-files] [-forms] text"
exit 1;;
*) text=$@
break;;
esac
shift
done
if [ $files = true ]
then
echo files:
find . -name "*.f" -print|xargs grep `cat grep_args` "$text"|pg
fi
if [ $forms = true ]
then
echo forms:
find . -name "*.s" -print|xargs grep `cat grep_args` "$text"|pg
fi