Subject: Re: grep - limited number of arguments?
From: "Conrad Scott" <[email-masked]>
To: "Thomas Baker" <[email-masked]>
Cc: <[email-masked]>
Date: Wed, 26 Jun 2002 12:37:10 +0100

"Thomas Baker" <[email-masked]> wrote:
> One difficulty I have found, however, is limitations (or so
> it would seem) on the number of arguments that the command
> "grep" can take.

You can't (portably) rely on anything much more than a few thousand
characters in a single command line. The minimum requirement for a
Posix system is 4096 (see <limits.h>). The usual technique is to use
`xargs', as:

    ls | xargs grep pattern

(or even `ls | xargs grep pattern /dev/null' to catch the case with
only one argument being given to grep and it changing behaviour).

This splits up the incoming arguments and invokes grep repeatedly, a
batch of the arguments at a time. It's particularly useful with `find'
and it's got lots of lovely options to play with too :-)

It would be nice to allow arbitrary command lines, but I've never
(knowingly) used a system that did so.

// Conrad

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/