grep is always recursive
loic.grenie at gmail.com
Thu Jan 29 10:07:46 UTC 2009
2009/1/29 Lorenzo Luengo <lluengo at dgeo.udec.cl>:
> Matthew Flaschen wrote:
>> 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...
>> It's a "design decision", and it's not going to be changed any time soon
>> (READ: ever). However, the given workarounds do work reliably.
>> $ grep "lala" *
>> $ grep -- "lala" *
>> will cause the option-looking directory to be ignored.
> This makes me think of those poor bash script developers that don't know
> which filenames they will be handling... I think that a good fix to this
> problem could be adding an option like"--files=*", that handles a
> regular expression for filtering files.
> Do you think of it to be a good idea?
I do not think so: * is intended to be expanded by the shell.
In that case, you would need the * to be expanded by the
program (probably through libc). Several shells have their own
version of glob patterns (I use zsh which is rather prolific) and
you cannot expect that the programs/library will have a version
of each glob pattern that they will choose according to which
shell has started the command; otherwise --files=*(.) will
not be equivalent to *(.) in zsh and I (and others) would be
The better solution (to me) would be that grep and other
programs be POSIXLY_CORRECT by default (unless the
user wishes that it is GNU_POSIX_EXTENDED). Since
this one is impossible, I'd let as is, and set
Just my .02€,
More information about the ubuntu-users