From owner-freebsd-hackers@FreeBSD.ORG Mon Mar 19 14:52:48 2007 Return-Path: X-Original-To: freebsd-hackers@FreeBSD.ORG Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id DCBF816A402 for ; Mon, 19 Mar 2007 14:52:48 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (lurza.secnetix.de [83.120.8.8]) by mx1.freebsd.org (Postfix) with ESMTP id 459F013C483 for ; Mon, 19 Mar 2007 14:52:47 +0000 (UTC) (envelope-from olli@lurza.secnetix.de) Received: from lurza.secnetix.de (fybura@localhost [127.0.0.1]) by lurza.secnetix.de (8.13.4/8.13.4) with ESMTP id l2JEqfFi044820; Mon, 19 Mar 2007 15:52:47 +0100 (CET) (envelope-from oliver.fromme@secnetix.de) Received: (from olli@localhost) by lurza.secnetix.de (8.13.4/8.13.1/Submit) id l2JEqfkp044819; Mon, 19 Mar 2007 15:52:41 +0100 (CET) (envelope-from olli) Date: Mon, 19 Mar 2007 15:52:41 +0100 (CET) Message-Id: <200703191452.l2JEqfkp044819@lurza.secnetix.de> From: Oliver Fromme To: freebsd-hackers@FreeBSD.ORG, youshi10@u.washington.edu In-Reply-To: <45FC61FF.3090009@u.washington.edu> X-Newsgroups: list.freebsd-hackers User-Agent: tin/1.8.2-20060425 ("Shillay") (UNIX) (FreeBSD/4.11-STABLE (i386)) MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.1.2 (lurza.secnetix.de [127.0.0.1]); Mon, 19 Mar 2007 15:52:47 +0100 (CET) Cc: Subject: Re: Possible grep(1) bug or user error :)? X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: freebsd-hackers@FreeBSD.ORG, youshi10@u.washington.edu List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Mar 2007 14:52:48 -0000 Garrett Cooper wrote: > I was recently grepping a directory and outputting to a file located in > the same directory as follows: > > grep -ri {key} * > {key}.found > > The thing is that grep kept on feeding off of the {key}.found file and > eventually ate up all the free space on the device (~12GB). > > Thankfully it wasn't one of my primary devices, so deleting it wasn't an > issue. However I was wondering if this case should be considered (in > error checking) and another option should be added to output grep info > to a file, instead of /dev/stdout, which would affect the behavior of > the --exclude flag (i.e. the output file would automatically be added to > --exclude's relevant array of non-searched arguments). It's not a problem with grep, it's a problem with your shell. Obviously you're using csh or tcsh, which create any files for redirection _first_, and then expand wildcards, so the redirected file is included in the expansion. That's one of the reasons csh/tcsh is considered harmful. :-) No other shell has that behaviour, i.e. all of sh, ksh, zsh and bash expand the wildcard first, then create the file for redirection, so it is not included in the expansion of the wildcard (unless it already existed before, of course). Best regards Oliver -- Oliver Fromme, secnetix GmbH & Co. KG, Marktplatz 29, 85567 Grafing b. M. Handelsregister: Registergericht Muenchen, HRA 74606, Geschäftsfuehrung: secnetix Verwaltungsgesellsch. mbH, Handelsregister: Registergericht Mün- chen, HRB 125758, Geschäftsführer: Maik Bachmann, Olaf Erb, Ralf Gebhart FreeBSD-Dienstleistungen, -Produkte und mehr: http://www.secnetix.de/bsd "In My Egoistical Opinion, most people's C programs should be indented six feet downward and covered with dirt." -- Blair P. Houghton