GNU bug report logs -
#30451
I found problem not solved to my grep
Previous Next
Reported by: Budi <budikusasi <at> gmail.com>
Date: Wed, 14 Feb 2018 02:47:01 UTC
Severity: normal
Tags: notabug
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
Full log
Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):
I believe that this is a problem with using shell quoting and spacing.
The following code works better for me:
========================
g()
{
if [ -n "$2" ]
then
i=
for s in $2
do
if [ -n "$i" ]
then
i="$i --include=*.$s"
else
i="--include=*.$s"
fi
done
else
i='--include=*.txt --include=*.ini --include=*.*sh --include=*.c*
--include=*.h --include=*.js --include=*.reg'
fi
grep -P -e "$1" -r $i
}
========================
The two changes I made:
1) Avoid putting a space at the front of the first "--include=*.$s" argument.
2) Double quote, not escaped single quote, the "$1" parameter to grep.
The parameter " --include=*.ini" was not a valid "--include" argument to
grep; rather it looked like a filename to grep, as its first character was a space.
The escaped single quotes around the "$1" parameter meant that you were
not looking for the three character pattern "sys", but rather for the five
character pattern "'sys'" (which is less likely to have appeared in your
test data.)
--
Paul Jackson
pj <at> usa.net
This bug report was last modified 5 years and 194 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.