command "grep" or redirection going in a loop.

Bug #245940 reported by Vaneet Dadra
8
Affects Status Importance Assigned to Milestone
grep
Unknown
Unknown
grep (Ubuntu)
Won't Fix
Undecided
Pascal De Vuyst

Bug Description

Hi,

I am working on a project and I am using grep command very frequently and found an interesting problem in it. For a particular path and if I grep some particular word and redirect the output to a file then it usually go into a loop and I have to find appropriate filename by random trials so that I do not go into loop. I have installed ubuntu 8.04. If you need any information about my computer and anything else then just shoot me an email.

ProblemType: Bug
Architecture: i386
Date: Sat Jul 5 22:07:16 2008
DistroRelease: Ubuntu 8.04
ExecutablePath: /usr/bin/nautilus
NonfreeKernelModules: nvidia
Package: nautilus 1:2.22.3-0ubuntu2
PackageArchitecture: i386
ProcEnviron:
 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
 LANG=en_IN
 SHELL=/bin/bash
SourcePackage: nautilus
Uname: Linux 2.6.24-19-generic i686

Tags: apport-bug
Revision history for this message
Vaneet Dadra (vaneet-dadra) wrote :
Revision history for this message
Pascal De Vuyst (pascal-devuyst) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better. Unfortunately we can't fix it, because your description didn't include enough information. We'd be grateful if you would then provide a more complete description of the problem.
At a minimum, we need:
1. the specific steps or actions you took that caused you to encounter the problem,
2. the behavior you expected, and
3. the behavior you actually encountered (in as much detail as possible).
Thanks!

Revision history for this message
Vaneet Dadra (vaneet-dadra) wrote : Re: [Bug 245940] Re: command "grep" or redirection going in a loop.

Hi,

I started the terminal then changed my working directory to
~/Vaneet_LRR/lrr/ and then typed the commnad "grep MAX -r ../lrr > t" and it
went into loop I presssed CTRL+C and removed the file t by "rm t" and then
tried the same command with filename "ch" it also went into loop and same
with filename "o", then I pressed CTRL+C and looked at the contents of file
"o" and found that it went into loop after finding mathces it started
looking in this file and it kept going on and on.
then I just changed my directory to ~/Vaneet_LRR/ and gave the command "grep
MAX -r lrr > t" and it worked.

On Sun, Jul 6, 2008 at 3:53 AM, Pascal De Vuyst <email address hidden>
wrote:

> Thank you for taking the time to report this bug and helping to make Ubuntu
> better. Unfortunately we can't fix it, because your description didn't
> include enough information. We'd be grateful if you would then provide a
> more complete description of the problem.
> At a minimum, we need:
> 1. the specific steps or actions you took that caused you to encounter the
> problem,
> 2. the behavior you expected, and
> 3. the behavior you actually encountered (in as much detail as possible).
> Thanks!
>
> ** Changed in: ubuntu
> Assignee: (unassigned) => Pascal De Vuyst (pascal-devuyst)
> Status: New => Incomplete
>
> --
> command "grep" or redirection going in a loop.
> https://bugs.launchpad.net/bugs/245940
> You received this bug notification because you are a direct subscriber
> of the bug.
>

--
Thank you and best regards,
Vaneet Dadra
www.cse.iitd.ac.in/~cs1060188

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

I can't reproduce this neither in Hardy nor Intrepid. Is it still an issue ?

Revision history for this message
Vaneet Dadra (vaneet-dadra) wrote :

Sometimes grep does go in loop but I don't know the exact cause to that. I
have explained the situations already.

On Wed, Sep 24, 2008 at 1:59 AM, Jean-Baptiste Lallement <
<email address hidden>> wrote:

> I can't reproduce this neither in Hardy nor Intrepid. Is it still an
> issue ?
>
> --
> command "grep" or redirection going in a loop.
> https://bugs.launchpad.net/bugs/245940
> You received this bug notification because you are a direct subscriber
> of the bug.
>

--
Thank you and best regards,
Vaneet Dadra
www.cse.iitd.ac.in/~cs1060188

Changed in grep:
status: Incomplete → New
Revision history for this message
Lesmana Zimmer (lesmana) wrote :

i think this would be the upstream bug (note: the comments are sorted newest first): http://savannah.gnu.org/bugs/?17457

strangely the mailing list thread for this bug goes longer than the actual bug: report http://<email address hidden>/msg00770.html

bottom line seems to be that this behaviour is by design (it's not a bug, it's a feature). when you redirect the results of grep into a file, and grep comes around to look at that file, then grep will find occurences infinitely. why this does not occur all the time seems to be a side effect of some buffers.

@Vaneet Dadra
you can prevent the infinite loop by redirecting the results to a file outside or above the tree you are grepping:
$ grep MAX -r somedirectory > ../somefile

Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

Setting the status to "won't fix" according to upstream comment.

If someone can provide a patch based on the upstream original reporter comment :"One way to solve this problem would be to prevent grep from searching inside a file if that file is associated with stdout. `cat' has that feature. I'll submit a patch based on cat's implementation." then feel free to reopen.

Thanks.

Changed in grep (Ubuntu):
status: New → Won't Fix
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.