Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.

Bug 1256756

Summary: grep -r has been broken in RHEL 6.7
Product: Red Hat Enterprise Linux 6 Reporter: sivathanu <sivathanut>
Component: grepAssignee: Jaroslav Škarvada <jskarvad>
Status: CLOSED ERRATA QA Contact: Jan Kepler <jkejda>
Severity: urgent Docs Contact:
Priority: urgent    
Version: 6.7CC: bnater, cww, fkrska, isenfeld, jdeenada, jesusislordcrom, jkejda, mkolaja, ovasik, pdwyer, salmy
Target Milestone: rcKeywords: Patch, Regression, ZStream
Target Release: ---   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: grep-2.20-5.el6 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of:
: 1367309 (view as bug list) Environment:
Last Closed: 2017-03-21 11:32:54 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Bug Depends On:    
Bug Blocks: 1269194, 1355829, 1356054, 1367309    
Attachments:
Description Flags
Proposed fix
none
Proposed fix none

Description sivathanu 2015-08-25 12:10:05 UTC
Description of problem:
When using "grep -r / grep -R", it not works as expected

Version-Release number of selected component (if applicable):
grep-2.20-3.el6.x86_64

How reproducible:
Whenever performing grep with -r/R, it failed to list expected result

Steps to Reproduce:
1.Navigate to coommand prompt and enter
 rpm -qa | grep -r grep


Actual results:

.bash_history:rpm -qa | grep -ir mysql
.bash_history:rpm -qa | grep -r mysql
.bash_history:rpm -qa | grep -r vsftp
.bash_history:rpm -qa | grep -r vsftpd
.bash_history:rpm -qa | grep -r sftp
.bash_history:ls | grep -ir "dhcp"
.bash_history:ls | grep -r "dhcp"
etc...


Expected results:
grep-2.20-3.el6.x86_64

Additional info:

It works fine in RHEL 6.6 and lower versions.

Comment 2 Jaroslav Škarvada 2015-08-25 14:15:05 UTC
It works according to documentation:

$ man grep
-r, --recursive
Read all files under each directory, recursively, following symbolic links only if they are on the command line. Note that if no file operand is given, grep searches the working directory. This is equivalent to the -d recurse option.

Is there file containing the string 'grep-2.20-3.el6.x86_64' in your working directory?

Comment 3 Jaroslav Škarvada 2015-08-25 14:28:32 UTC
(In reply to Jaroslav Škarvada from comment #2)
> It works according to documentation:
> 
> $ man grep
> -r, --recursive
> Read all files under each directory, recursively, following symbolic links
> only if they are on the command line. Note that if no file operand is given,
> grep searches the working directory. This is equivalent to the -d recurse
> option.
> 
> Is there file containing the string 'grep-2.20-3.el6.x86_64' in your working
> directory?

Correct man text from RHEL-6.7 grep:
-r, --recursive
Read all files under each directory, recursively, following symbolic links only if they are on the command line. This is equivalent to the -d recurse option.

It's missing the 'working directory' clarification, but the behaviour is according to the upstream documentation. We could update the manual page.

Comment 4 sivathanu 2015-08-25 14:58:27 UTC
I agree. When using grep only, the current behavior is correct. But using grep with result of "ls/rpm -qa" doesn't provide correct result.

Can please execute the following command in RHEL 6.6 & 6.7 and elaborate the difference? 

rpm -qa | grep -r grep

The result what i gathered from RHEL 6.6 & 6.7 are different. It made me to raise this bug.



(In reply to Jaroslav Škarvada from comment #3)
> (In reply to Jaroslav Škarvada from comment #2)
> > It works according to documentation:
> > 
> > $ man grep
> > -r, --recursive
> > Read all files under each directory, recursively, following symbolic links
> > only if they are on the command line. Note that if no file operand is given,
> > grep searches the working directory. This is equivalent to the -d recurse
> > option.
> > 
> > Is there file containing the string 'grep-2.20-3.el6.x86_64' in your working
> > directory?
> 
> Correct man text from RHEL-6.7 grep:
> -r, --recursive
> Read all files under each directory, recursively, following symbolic links
> only if they are on the command line. This is equivalent to the -d recurse
> option.
> 
> It's missing the 'working directory' clarification, but the behaviour is
> according to the upstream documentation. We could update the manual page.

Comment 5 Jaroslav Škarvada 2015-08-25 16:22:02 UTC
The current behaviour is logical and intended by upstream, from Paul Eggert commit:

    This is a patch I've been meaning to put in for years.
    When I added support for "grep -r", I forgot to have "grep -r PAT"
    search the working directory by default, instead of searching
    standard input (which makes no sense, even if stdin is a directory).
    This is not an upward compatible change, since "grep -r PAT <file"
    will no longer search standard input, but that's OK; nobody should
    be using "grep -r" that way anyway.

I agree it's change in behaviour, but the previous behaviour wasn't correct. In case it's problem for you, please escalate this through the support channel, the old behaviour could be "forward ported", but it's something I would like to avoid if not necessary.

Comment 8 Jaroslav Škarvada 2016-04-07 09:48:14 UTC
The problem:

old behaviour:
"grep -r PATTERN"   - reads STD INPUT (-r is ignored)
"grep -r PATTERN ." - recursively scans current directory for files containing the PATTERN

New behaviour:
"grep -r PATTERN"   - recursively scans current directory for files containing the PATTERN
"grep -r PATTERN ." - recursively scans current directory for files containing the PATTERN

I think we need compatibility environment switch.

Comment 16 Jaroslav Škarvada 2016-06-15 14:42:11 UTC
Created attachment 1168411 [details]
Proposed fix

Comment 17 Jaroslav Škarvada 2016-06-15 14:57:57 UTC
Scratch build for testing:
http://people.redhat.com/jskarvad/rhbz1256756/

GREP_LEGACY_R=1 - means old behavior

Comment 19 Jaroslav Škarvada 2016-06-15 22:37:29 UTC
Created attachment 1168529 [details]
Proposed fix

Comment 29 errata-xmlrpc 2017-03-21 11:32:54 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2017-0756.html