[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Grep: --quiet & suggestion
From: |
Paul Eggert |
Subject: |
Re: Grep: --quiet & suggestion |
Date: |
09 Jun 2003 12:04:04 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
Stepan Kasal <address@hidden> writes:
> On Sun, Jun 08, 2003 at 12:02:58PM +0300, Jori Mantysalo wrote:
> > $ (grep -m 1 cat ; grep -m 1 dog) < text && echo 'Found!'
> > cat
> > dog
> > Found!
>
> well, even though this works on my system too, the folowing doesn't:
>
> $ (echo cat;echo dog) | (grep -m 1 cat; grep -m 1 dog)
> cat
> $
>
> In any way I wouldn'd use grep this way.
>
> I tend to say that the bug is that ``grep'' doesn't close its input file
> after the -m limit is reached. When this bug is fixed, the above command
> won't work in any case.
That's OK. POSIX says:
When a standard utility reads a seekable input file and terminates
without an error before it reaches end-of-file, the utility shall
ensure that the file offset in the open file description is properly
positioned just past the last byte processed by the utility. For
files that are not seekable, the state of the file offset in the
open file description for that file is unspecified.
<http://www.opengroup.org/onlinepubs/007904975/utilities/xcu_chap01.html#tag_01_11>
(under INPUT FILES)
So even though -m 1 stops after the matching line, it's not required
to work that way when reading from a pipe, since a pipe is not
seekable.