--include does the same as --exclude!

Bug #651867 reported by Olaf Lenz
This bug report is a duplicate of:  Bug #1003742: grep 2.9 --include not working. Edit Remove
32
This bug affects 6 people
Affects Status Importance Assigned to Milestone
grep (Ubuntu)
Confirmed
Undecided
Unassigned
Nominated for Maverick by Olaf Lenz

Bug Description

Binary package hint: grep

> lsb_release -rd
Description: Ubuntu maverick (development branch)
Release: 10.10

I'm using maverick beta that contains grep 2.6.3.

When using the '--include' option to grep (mainly used for recursive matching), grep 2.6.3 does not behave as expected. In fact, it works like '--exclude', but only in the top level directory.

Example:
1. Create a subdirectory that contains two files "file.has" and "file.hasnot". Both files contain only the string 'test'.
>mkdir test
>cd test
>echo "test" > file.has
>echo "test" > file.hasnot

2. Now I do:
> grep --include="file.has" -l test *
file.hasnot

I would expect the command to output "file.has". The behavior shown is the behavior of "--exclude":

> grep --exclude="file.has" -l test *
file.hasnot

This is not a very practical example and doesn't show the maximal confusion. So another demonstration:

1. Create a new subdirectory and make an additional copy of the files into the subdir.
> mkdir sub
> cp file.* sub/

2. Now do the above commands recursively:
> grep -rl --include="file.has" test *
file.hasnot
sub/file.has
> grep -rl --exclude="file.has" test *
file.hasnot
sub/file.hasnot

This is definitely not the expected behavior.

I have built an up-to-date grep (grep 2.7) from the GNU homepage, and this does not have the problematic behavior, so I guess the best solution is to upgrade grep.

Revision history for this message
Peter Clifton (pcjc2) wrote :

Upstream fix is here:

http://git.savannah.gnu.org/cgit/grep.git/commit/?id=9c45c193825d1f59e1d341e556ecf4adeb7a03a2

author Jim Meyering <email address hidden> 2010-08-13 23:19:16 (GMT)
committer Jim Meyering <email address hidden> 2010-08-13 23:58:39 (GMT)
commit 9c45c193825d1f59e1d341e556ecf4adeb7a03a2 (patch)
tree 45f3d1f2946c96503c5087e36706170ea9684b47
parent 3569576a3304b51491be0a88d4659713d960674f (diff)
download grep-9c45c193825d1f59e1d341e556ecf4adeb7a03a2.tar.gz
make --include=FILE work once again
The semantics of excluded_file_name changed (when operating on
an "included" file name list).
* src/main.c (main): Adjust for changed semantics of excluded_file_name
simply by removing a negation.
* NEWS (Bug fixes): Mention this fix.
* tests/include-exclude: Add a test for this.
Reported by Joe Perches in http://savannah.gnu.org/bugs/?29876.

Changed in grep (Ubuntu):
status: New → Confirmed
Revision history for this message
Margarita Manterola (marga-9) wrote :

Hi, this bug was supposedly fixed, but then it was broken again. This is also reported in:
https://bugs.launchpad.net/ubuntu/+source/grep/+bug/1003742

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.