grep is always recursive

Matthew Flaschen matthew.flaschen at
Thu Jan 29 23:21:06 UTC 2009

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, then do:

chmod a+x
mkdir author_test
touch author_test/JES_proposal.txt
cd author_test
../ *

It will print:

JES_proposal.txt: John Edwards Smith

If you do:

../ ./JES_proposal.txt

(the latter is what your proposal entails), it will give:

./JES_proposal.txt: Author not found

Matthew Flaschen


for filename in "$@"
    echo -n "$filename: "
    case $filename in
	    echo "John Edwards Smith"
	    echo "Mary Jane Thompson"
	    echo "Author not found";

More information about the ubuntu-users mailing list