bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with grep


From: Bob Proulx
Subject: Re: Problem with grep
Date: Wed, 25 Jun 2014 17:02:19 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

Berlin, Eric wrote:
> I have never written to an organization of this sort before, but I

Welcome!

> have run into a problem with grep that I cannot find a reasonable

Writing here to the generic bug-gnu-utils is fine.  It is a
catch-all.  However for grep there is a specific mailing list for
dealing with all things grep.  After our exchange here if things do
not get resolved for you then please write to the address@hidden
mailing list where the grep developers will see it.

  grep --help | grep @
  Report bugs to: address@hidden

There is another catch-all that I want to mention too.  The
help-gnu-utils mailing list is for general help.  If you don't know
where else to go then that is a good place to start.  This is just
additional information to file away for the future.

> answer for no matter how hard I read the man page or google. My grep
> version is grep (GNU grep) 2.5.1-FreeBSD and I have many grep lines
> in my bash shell script but here is a typical one:
> 
> grep -m 1 "FAILED.*Hardware inventory tool" "$D/output_log"|wc -l|tr -d '\n' 
> >> arrayfile
> 
> I repeatedly get the following error when I run the script;
> 
> "grep: Invalid max count"

Hmm...  That does not seem possible with the above type of command.

(As a separate unrelated thing I must wonder about the purpose of the
"tr -d '\n'" part to delete newlines before append to the file.  That
just seems strange.)

> I have tried several small programs as experiments but can't
> reproduce the problem that way. I did notice that the file
> "output_log" contains '-A' in it and thought that was causing the
> problem, but my small programs don't cause the above error.
> 
> So, my question - Is this a bug or expected behavior?

If grep is producing that error then it is definitely expected
behavior in the presence of invalid -m input.  For example:

  $ grep -m "" 
  grep: invalid max count

I doubt this is a bug in grep.  Very likely it is a bug in the script.
Especially since you haven't been able to trigger it in grep
otherwise.

I know you have been looking at it but you didn't share enough with us
to really know what is going on.  I am sure that once you find the
problem that it will make sense.  It looks to me like an invalid -m
argument just as the message says.

Have you been using -x to debug your script?  I often debug shell
scripts by tracing the command execution.

  sh -x /path/to/script 2>&1 | tee /tmp/script.trace

Use the appropriately matching command.  "sh" for "#!/bin/sh" but
"bash" for "#!/bin/bash" and so forth.  The above might not be
appropriate all of the time.  It all depends and all of that.

In the tracing output you will see the actual arguments to the grep
command.  I am sure that it will confirm an invalid -m argument.

There are some other tricks that can be used to locate these things
too.  Write back for more discussion.

Bob



reply via email to

[Prev in Thread] Current Thread [Next in Thread]