Date: Mon, 19 Mar 2007 15:52:41 +0100 (CET) From: Oliver Fromme <olli@lurza.secnetix.de> To: freebsd-hackers@FreeBSD.ORG, youshi10@u.washington.edu Subject: Re: Possible grep(1) bug or user error :)? Message-ID: <200703191452.l2JEqfkp044819@lurza.secnetix.de> In-Reply-To: <45FC61FF.3090009@u.washington.edu>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200703191452.l2JEqfkp044819>