GNU bug report logs - #16965
Likely bug in grep for file without an ending newline

Previous Next

Package: grep;

Reported by: Abramo Bagnara <abramo.bagnara <at> gmail.com>

Date: Fri, 7 Mar 2014 22:45:02 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 16965 in the body.
You can then email your comments to 16965 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#16965; Package grep. (Fri, 07 Mar 2014 22:45:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Abramo Bagnara <abramo.bagnara <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-grep <at> gnu.org. (Fri, 07 Mar 2014 22:45:03 GMT) Full text and rfc822 format available.

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

From: Abramo Bagnara <abramo.bagnara <at> gmail.com>
To: jim <at> meyering.net, mark.veltzer <at> gmail.com, bug-grep <at> gnu.org
Subject: Likely bug in grep for file without an ending newline
Date: Fri, 07 Mar 2014 23:38:12 +0100
$ echo -n test > file
$ fgrep e file
test
$ fgrep -v q file
test
$ cat file
test$

My expectation would be that file is not altered by grep if all lines
matches pattern.

Is current grep behavior the expected one?


-- 
Abramo Bagnara




Information forwarded to bug-grep <at> gnu.org:
bug#16965; Package grep. (Sat, 08 Mar 2014 00:53:01 GMT) Full text and rfc822 format available.

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

From: Jim Meyering <jim <at> meyering.net>
To: Abramo Bagnara <abramo.bagnara <at> gmail.com>
Cc: bug-grep <at> gnu.org, mark.veltzer <at> gmail.com
Subject: Re: Likely bug in grep for file without an ending newline
Date: Fri, 7 Mar 2014 16:51:35 -0800
On Fri, Mar 7, 2014 at 2:38 PM, Abramo Bagnara <abramo.bagnara <at> gmail.com> wrote:
>
> $ echo -n test > file
> $ fgrep e file
> test
> $ fgrep -v q file
> test
> $ cat file
> test$
>
> My expectation would be that file is not altered by grep if all lines
> matches pattern.

Thank you for the report.
Grep is specified to operate on so-called "lines" which are defined
to end with a newline, so the moment you give grep an input that
does not consist of lines, you're in "unspecified" territory.  I.e., what
grep does with that input is unspecified by POSIX. We have
chosen to make it append the newline in that case.

> Is current grep behavior the expected one?

It is documented in "info grep":

  If the final byte of an input file is not a newline, `grep' silently
supplies one.




Added tag(s) notabug. Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Sat, 08 Mar 2014 15:34:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 16965 <at> debbugs.gnu.org and Abramo Bagnara <abramo.bagnara <at> gmail.com> Request was from Paul Eggert <eggert <at> cs.ucla.edu> to control <at> debbugs.gnu.org. (Sat, 08 Mar 2014 15:34:02 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. (Sun, 06 Apr 2014 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 136 days ago.

Previous Next


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