grep is always recursive

Lorenzo Luengo lluengo at
Tue Jan 27 20:45:35 UTC 2009

Hal Burgiss wrote:
> On Sat, Jan 24, 2009 at 08:51:49PM -0700, Smoot Carl-Mitchell wrote:
>> You do not happen to have a directory called "-r" in your home
>> directory.  That would cause the problem you are seeing.
> BINGO! That was indeed it. I never would have thought to look for
> that. Excellent work! Thanks all.

is it a bug?? or a feature??

I made a test with the following directory structure:

Then populated it with some files

echo "lala" > 1/1
echo "lala" > 2/1
echo "lala" > 3/1

Then i did:
$ grep "lala" *


Then i renamed that directory

mv ./-r ./.-r

$ grep "lala" *


The problem comes from the bash * expansion that makes grep see that 
filename as an option. Is it a bash problem? Is it a grep problem?? 
Don't know...

Should it be reported to anyone?

Lorenzo Luengo Contreras
Administrador de Sistemas DGEO
Universidad de ConcepciĆ³n
ConcepciĆ³n - Chile

More information about the ubuntu-users mailing list