grep is always recursive

Lorenzo Luengo lluengo at dgeo.udec.cl
Tue Feb 3 00:27:58 UTC 2009


Cameron Hutchison wrote:
> Lorenzo Luengo <lluengo at dgeo.udec.cl> writes:
>
>   
>> Matthew Flaschen wrote:
>>     
>>> Lorenzo Luengo wrote:
>>>   
>>>       
>>>> 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
>>>>         
>>> It's not backwards-compatible.  Below is a sample script that breaks.
>>> Granted, it's slightly contrived, but nonetheless a valid example.  To
>>> test it, save as author_from_initials.sh, then do:
>>>
>>> chmod a+x author_from_initials.sh
>>> mkdir author_test
>>> touch author_test/JES_proposal.txt
>>> cd author_test
>>> ../author_from_initials.sh *
>>>
>>> It will print:
>>>
>>> JES_proposal.txt: John Edwards Smith
>>>
>>> If you do:
>>>
>>> ../author_from_initials.sh ./JES_proposal.txt
>>>
>>> (the latter is what your proposal entails), it will give:
>>>
>>> ./JES_proposal.txt: Author not found
>>>
>>> (code snip)  
>>>       
>> But I think it doesn't work because the way you coded your case matching 
>> like JES*, but the filename is still correct and valid filename, and not 
>> an spurious option.
>>     
>
> It doesn't work because it's a poor script that cannot handle filenames
> with paths. The script would also fail with:
>
> $ author_from_initials.sh ~/doc/*
>
> But, more importantly, Matthew has misunderstood the proposal. Only
> filenames starting with a dash are prefixed with a ./ . He missed the
> part in your example where only -r was turned into ./-r. The other
> filenames were expanded as expected.
>
> Given the proposal, Matthew's script would continue to work as expected.
>
>
>   
Should we file an /enhancement proposal/ to the bash developers??

I keep thinking it's a good idea.

-- 
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