[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Possible bug with parameter -m
From: |
Benno Schulenberg |
Subject: |
Re: Possible bug with parameter -m |
Date: |
Tue, 26 Jun 2007 16:45:51 +0200 |
User-agent: |
KMail/1.9.7 |
Stefan Sassenberg wrote:
> Benno wrote:
> > Stefan Sassenberg wrote:
> > > I have a file named "file" containing three lines
> > > line1
> > > line2
> > > line3
> > >
> > > When I execute the following line in my bash
> > > "while true; do grep ^ -m 1 ; done <file"
> > > I expect the output
> > > line1
> > > line2
> > > line3
> > >
> > > after three loop runs, one for every line found in the file.
> >
> > That would indeed be the correct output. From the man page:
> > "If [...] NUM matching lines are output, grep ensures that
> > the standard input is positioned to just after the last
> > matching line before exiting [...]. This enables a calling
> > process to resume a search." The endless repetition of line2
> > in your example is a bug in grep.
> >
> > > I'm not sure what happened, but recently that doesn't work
> > > anymore.
> >
> > It did work in the past? With what version was that?
>
> It has worked always for me before. I used that behaviour in a
> script for years. Unfortunately I only call this script about
> once in two months. I tried to find if I had a change in the grep
> version in the near past, but I didn't find it out. That's the
> reason why I wrote "possible" bug.
Hmm... On the first partition of this disk I still have an old
Suse-9.0 installation, and grep there doesn't exhibit this wrong
behaviour. It might be that later distributions apply some patch
that causes the bug, or it might be that newer glibcs trigger this
bug in grep, or it might be a bug in those newer glibcs themselves.
I have no idea. And alas, the Charles Leverts and Claudio Fontanas
are gone.
# unset GREP_OPTIONS
# cat file
line1
xxx
zz
# while true; do /bin/grep ^ -m1 ; echo ==; done <file | head -12
line1
==
xxx
==
1
==
ne1
==
1
==
ne1
==
# while true; do /suse/bin/grep ^ -m1 ; echo ==; done <file | head
-12
line1
==
xxx
==
zz
==
==
==
==
==
==
==
# /suse/bin/grep --version | head -1
grep (GNU grep) 2.5.1
# /bin/grep --version | head -1
grep (GNU grep) 2.5.1
My system is an up-to-date Gentoo one, but an Ubuntu Feisty exhibits
the same error. So the most likely cause is some patch applied by
most distributions, because when running /suse/bin/grep it uses the
libc from my Gentoo system.
> Are you a grep developer?
No. The grep maintainer, Stepan Kasal, is missing in action. The
other maintainer, Bernhard Rosenkraenzer, is probably mostly busy
with ArkLinux. Grep has been dead for two and a half years now.
Benno