Possible grep(1) bug or user error :)?

James Bailie jimmy at mammothcheese.ca
Sat Mar 17 22:47:52 UTC 2007


Garrett Cooper wrote:
 > 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).

The shell is redirecting stdout onto the found file before it is
expanding the glob patterns, so the found file is being included
in the expansion.  You can force the expansion to occur first if
you assign it to a variable:

sh:

FILES=*; grep -ri key $FILES > found

csh:

set FILES=*; grep -ri key $FILES > found

Hope this helps,

-- 
James Bailie <jimmy at mammothcheese.ca>
http://www.mammothcheese.ca


More information about the freebsd-hackers mailing list