--include does the same as --exclude!
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
grep (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned | ||
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.hasnot
I would expect the command to output "file.has". The behavior shown is the behavior of "--exclude":
> grep --exclude=
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.hasnot
sub/file.has
> grep -rl --exclude=
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.
Upstream fix is here:
http:// git.savannah. gnu.org/ cgit/grep. git/commit/ ?id=9c45c193825 d1f59e1d341e556 ecf4adeb7a03a2
author Jim Meyering <email address hidden> 2010-08-13 23:19:16 (GMT) 9e1d341e556ecf4 adeb7a03a2 (patch) 03c5087e3670617 0ea9684b47 491be0a88d46597 13d960674f (diff) 5d1f59e1d341e55 6ecf4adeb7a03a2 .tar.gz exclude: Add a test for this. savannah. gnu.org/ bugs/?29876.
committer Jim Meyering <email address hidden> 2010-08-13 23:58:39 (GMT)
commit 9c45c193825d1f5
tree 45f3d1f2946c965
parent 3569576a3304b51
download grep-9c45c19382
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-
Reported by Joe Perches in http://