bug-grep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #17457] "grep -r foo . > somefile" goes into an infinite loop


From: Jim Meyering
Subject: Re: [bug #17457] "grep -r foo . > somefile" goes into an infinite loop
Date: Sat, 06 Feb 2010 16:57:28 +0100

Paolo Bonzini wrote:

>> Actually, how about detecting this and diagnosing
>> the problem rather than falling into the infloop?
>>
>> This currently evokes an infloop for me:
>>
>>      $ seq 1000000>  k
>>      $ grep 111 k>>  k
>>
>> However, simply detecting when the output FD is also an input FD is
>> not enough, since this variant does not get stuck:
>>
>>      $ seq 1000>  k
>>      $ grep 111 k>>  k
>
> Whether it gets stuck is mainly a function of the buffer size for the
> file.  Certainly whatever is added at the end of "k" matches, so it
> will be added over and over.
>
> This is a problem for every Unix utility that reads files sequentially
> (e.g. sed or, from coreutils, cut, cat, fmt, tail, comm).

True, of course, but when it's relatively easy to make the mistake,
it's can be worthwhile to detect it and help the user.
That's what sort does.

My example above was contrived, but the original one
in this bug report was not:

    grep -r pattern . > results




reply via email to

[Prev in Thread] Current Thread [Next in Thread]