grep is always recursive

Lorenzo Luengo lluengo at dgeo.udec.cl
Mon Feb 2 16:29:22 UTC 2009


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
>>
>> and everything should work as everyone intended.
>>     
>
> 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
>
> Matthew Flaschen
>
> --------------------------------------------------
>
> #!/bin/sh
> for filename in "$@"
> do
>     echo -n "$filename: "
>     case $filename in
> 	JES*)
> 	    echo "John Edwards Smith"
> 	    ;;
> 	MJT*)
> 	    echo "Mary Jane Thompson"
> 	    ;;
> 	*)
> 	    echo "Author not found";
> 	    ;;
>     esac
> done
>
>   
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.

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