grep is always recursive

Cameron Hutchison lists at
Wed Jan 28 04:31:31 UTC 2009

Matthew Flaschen <matthew.flaschen at> writes:

>Smoot Carl-Mitchell wrote:
>> On Tue, 2009-01-27 at 17:45 -0300, Lorenzo Luengo wrote:
>>> 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?
>> The root of the problem is the getopt function in the C library which is
>> the standard way of doing option processing in C programs.
>> The glob shell expansion of '*' is correct.

>Given the way the shell does expansion, and the way arguments are passed
>to C programs, how would you design get opt to eliminate this problem?
>I don't think it's possible to "fix" this in getopt (which is not used
>by all C programs anyway)

It could be fixed in the shell, rather than getopt. If a wildcard
expands to a filename starting with a -, prefix that with ./ .

This may break some esoteric scripts that do funny things with filename
expansion, but if it is done in bash rather than sh, it could be done
with an option to turn it off.

More information about the ubuntu-users mailing list