GNU bug report logs - #30451
I found problem not solved to my grep

Previous Next

Package: grep;

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.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 30451 in the body.
You can then email your comments to 30451 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-grep <at> gnu.org:
bug#30451; Package grep. (Wed, 14 Feb 2018 02:47:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Budi <budikusasi <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Wed, 14 Feb 2018 02:47:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Budi <budikusasi <at> gmail.com>
To: bug-grep <at> gnu.org
Subject: I found problem not solved to my grep
Date: Wed, 14 Feb 2018 08:59:47 +0700
[Message part 1 (text/plain, inline)]
 I tried to  customize grep:

Code:

g () {
if [ -n "$2" ]
then
 i=
 for s in $2
 do
	i="$i --include=*.$s"
 done
 else
	i='--include=*.txt --include=*.ini --include=*.*sh --include=*.c*
--include=*.h --include=*.js --include=*.reg'
fi
grep -P -e \'$1\' -r $i
}

or with double quote "$i" as tested and used below

Code:

$ g sys ini
grep:  --include=*.ini: No such file or directory

without it, ie. "", it'll just freeze awhile as if it processes properly,
if one inserts 'echo' to the last line for tracking and test:


echo grep -P -e \'$1\' -r $i

then reload the alias file and redo it,

Code:

$ g sys ini
grep -P -e 'sys' -r  --include=*.ini

it'll echo correctly to become perfectly a valid grep command line...
What's actually happened and how to fix and solve this ?
Thanks so much in advance.
[Message part 2 (text/html, inline)]

Information forwarded to bug-grep <at> gnu.org:
bug#30451; Package grep. (Wed, 14 Feb 2018 07:35:01 GMT) Full text and rfc822 format available.

Message #8 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Jackson <pj <at> usa.net>
To: bug-grep <at> gnu.org
Subject: Re: bug#30451: I found problem not solved to my grep
Date: Wed, 14 Feb 2018 01:34:14 -0600
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




Added tag(s) notabug. Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Tue, 31 Dec 2019 20:59:01 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 30451 <at> debbugs.gnu.org and Budi <budikusasi <at> gmail.com> Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Tue, 31 Dec 2019 20:59:01 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 29 Jan 2020 12:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 4 years and 60 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.