GNU bug report logs - #25651
Weird output of random files

Previous Next

Package: grep;

Reported by: "rexkogitans <at> gmx.at" <rexkogitans <at> gmx.at>

Date: Tue, 7 Feb 2017 20:32:01 UTC

Severity: normal

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 25651 in the body.
You can then email your comments to 25651 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#25651; Package grep. (Tue, 07 Feb 2017 20:32:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to "rexkogitans <at> gmx.at" <rexkogitans <at> gmx.at>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Tue, 07 Feb 2017 20:32:01 GMT) Full text and rfc822 format available.

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

From: "rexkogitans <at> gmx.at" <rexkogitans <at> gmx.at>
To: bug-grep <at> gnu.org
Subject: Weird output of random files
Date: Tue, 7 Feb 2017 21:24:32 +0100
[Message part 1 (text/plain, inline)]
Hello,

I could repeatedly reproduce an unexpected behaviour on several Linux 
systems (two installations of Arch Linux [newest state], a Debian [8.7] 
and a Ubuntu [16.4]).

I ran the following command - when I first ran it, it was accidentially

ps ax | grep -reh

I wanted to grep for processes containing the string "-reh", but forgot 
the "-e" which was necessary due to the leading dash in the string.

On all systems, grep outputs hundreds of (not even matching) lines from 
files of my home directory, not at all related to the output of ps, 
which I piped into grep.

Maybe, the command line is interpreted as:

   * r ... search files recursively in directories. Note, that input is
   read from stdin here.

   * e ... use the following pattern

   * h ... this is the pattern expected by "e"

It may be that all the lines ouput by grep contain "h".

Although expected to be identical, this command works as expected:

ps ax | grep -reh /dev/stdin

Kind regards,

rexkogitans


[Message part 2 (text/html, inline)]

Reply sent to Paul Eggert <eggert <at> cs.ucla.edu>:
You have taken responsibility. (Tue, 07 Feb 2017 22:32:02 GMT) Full text and rfc822 format available.

Notification sent to "rexkogitans <at> gmx.at" <rexkogitans <at> gmx.at>:
bug acknowledged by developer. (Tue, 07 Feb 2017 22:32:03 GMT) Full text and rfc822 format available.

Message #10 received at 25651-done <at> debbugs.gnu.org (full text, mbox):

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: "rexkogitans <at> gmx.at" <rexkogitans <at> gmx.at>, 25651-done <at> debbugs.gnu.org
Subject: Re: bug#25651: Weird output of random files
Date: Tue, 7 Feb 2017 14:30:56 -0800
On 02/07/2017 12:24 PM, rexkogitans <at> gmx.at wrote:
> Maybe, the command line is interpreted as:
>
>    * r ... search files recursively in directories. Note, that input is
>    read from stdin here.
>
>    * e ... use the following pattern
>
>    * h ... this is the pattern expected by "e"

Yes, that's the interpretation that 'grep' uses, except that it reads 
input from ".", not from stdin. That is, 'grep -r PAT' is equivalen to 
'grep -r PAT .'. This is for convenience: as it does not make sense to 
use -r on an input stream, the default input is '.' instead of '-' when 
-r is used.

grep cannot "know" that the user wanted it to read from stdin, for the 
same reason that it does not "know" that the user wanted it to read from 
stdin here:

   ps ax | grep 0:00 xyz

This causes 'grep' to read from the file 'xyz', instead of the desired 
behavior of looking for the pattern '0:00 xyz' in the 'ps ax' output. 
The 'ps ax' output is ignored.





Information forwarded to bug-grep <at> gnu.org:
bug#25651; Package grep. (Wed, 08 Feb 2017 21:33:02 GMT) Full text and rfc822 format available.

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

From: "rexkogitans <at> gmx.at" <rexkogitans <at> gmx.at>
To: 25651 <at> debbugs.gnu.org
Subject: Re: bug#25651: closed (Re: bug#25651: Weird output of random files)
Date: Wed, 8 Feb 2017 22:12:33 +0100
Thanks for the clearance, but this behaviour is very ... unexpected.


ps ax | grep 0:00 xyz


is clear that the second parameter is meant to be interpreted as 
filename, otherwise it should read

ps ax | grep '0:00 xyz'

But I was not expecting "." instead of "-" when option -r is in use. 
Maybe this could be added in the man page.

Kind regards,

rexkogitans


On 2017-02-07 23:32, GNU bug Tracking System wrote:
> Your bug report
>
> #25651: Weird output of random files
>
> which was filed against the grep package, has been closed.
>
> The explanation is attached below, along with your original report.
> If you require more details, please reply to 25651 <at> debbugs.gnu.org.
>





Information forwarded to bug-grep <at> gnu.org:
bug#25651; Package grep. (Wed, 08 Feb 2017 23:36:01 GMT) Full text and rfc822 format available.

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

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: "rexkogitans <at> gmx.at" <rexkogitans <at> gmx.at>, 25651 <at> debbugs.gnu.org
Subject: Re: bug#25651: closed (Re: bug#25651: Weird output of random files)
Date: Wed, 8 Feb 2017 15:35:12 -0800
On 02/08/2017 01:12 PM, rexkogitans <at> gmx.at wrote:
> Maybe this could be added in the man page.

It is already mentioned there, no? 'grep --help' says "With no FILE, 
read . if a command-line -r is given, - otherwise." Perhaps the wording 
could be improved; if so, specific wording suggestions would help.





Information forwarded to bug-grep <at> gnu.org:
bug#25651; Package grep. (Fri, 10 Feb 2017 20:05:02 GMT) Full text and rfc822 format available.

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

From: "rexkogitans <at> gmx.at" <rexkogitans <at> gmx.at>
To: Paul Eggert <eggert <at> cs.ucla.edu>, 25651 <at> debbugs.gnu.org
Subject: Re: bug#25651: closed (Re: bug#25651: Weird output of random files)
Date: Fri, 10 Feb 2017 21:03:44 +0100
[Message part 1 (text/plain, inline)]
Hello, Paul,
this is correct, it is mentioned in grep --help. However, I always
expect the man pages to be more exhaustive. But here, it only says
grep searches the named input FILEs for lines containing a match to the
given PATTERN.  If no files are specified, or if the file “-” is given,
grep  searches  standard  input.   Bydefault, grep prints the matching
lines.
Well, of course, in the description of --recursive, it is mentioned:
      -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.
This could be made a bit more consistent.
grep searches the named input FILEs for lines containing a match to the
given PATTERN.  If no files are specified, or if the file “-” is given,
grep  searches  standard  input or, by using the --recursive switch,
the current directory.   By default, grep prints the matching lines.
If I am the first in the world to fall for this, then please consider
this discussion as useless. This bug report is closed, anyway.
Kind regards,rexkogitans
Am Mittwoch, den 08.02.2017, 15:35 -0800 schrieb Paul Eggert:
> On 02/08/2017 01:12 PM, rexkogitans <at> gmx.at wrote:
> > Maybe this could be added in the man page.
> 
> It is already mentioned there, no? 'grep --help' says "With no FILE, 
> read . if a command-line -r is given, - otherwise." Perhaps the
> wording 
> could be improved; if so, specific wording suggestions would help.
> 
[Message part 2 (text/html, inline)]

Information forwarded to bug-grep <at> gnu.org:
bug#25651; Package grep. (Sun, 12 Feb 2017 21:46:02 GMT) Full text and rfc822 format available.

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

From: Paul Eggert <eggert <at> cs.ucla.edu>
To: "rexkogitans <at> gmx.at" <rexkogitans <at> gmx.at>, 25651 <at> debbugs.gnu.org
Subject: Re: bug#25651: closed (Re: bug#25651: Weird output of random files)
Date: Sun, 12 Feb 2017 13:45:16 -0800
[Message part 1 (text/plain, inline)]
rexkogitans <at> gmx.at wrote:
> This could be made a bit more consistent.

Fair enough, I installed the attached.
[0001-doc-clarify-default-input-Bug-25651.patch (text/x-diff, attachment)]

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 13 Mar 2017 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 8 years and 158 days ago.

Previous Next


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