grep is always recursive

Lorenzo Luengo lluengo at dgeo.udec.cl
Thu Jan 29 04:50:50 UTC 2009


Matthew Flaschen wrote:
> Cameron Hutchison wrote:
>   
>>> 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 ./ .
>>     
>
> Except the standard says, "The slash character in a pathname shall be
> explicitly matched by using one or more slashes in the pattern; it shall
> neither be matched by the asterisk or question-mark special characters
> nor by a bracket expression"
>
> In other words, * can not match a /.
>
> If you want paths to start with ./, you need to put ./*
>
>   
>> 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.
>>     
>
> Bash should be backwards-compatible with sh by /default/.
>
>   
I think it's also a great idea. And it does not break backwards 
compatibility! Let's see our study case:

$ ls
somefile   -r somotherfile

Now when you do
$ grep someword *

It would expand to
$ grep someword somefile ./-r somotherfile

and everything should work as everyone intended.

-- 
Lorenzo Luengo Contreras
Administrador de Sistemas DGEO
Universidad de ConcepciĆ³n
ConcepciĆ³n - Chile
+56-41-2207277





More information about the ubuntu-users mailing list