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

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

Re: grep: return code with -v and empty input


From: tt
Subject: Re: grep: return code with -v and empty input
Date: 20 Mar 2001 20:58:26 +0200

address@hidden (Edward Avis) writes:

> According to the documentation, the -v flag is supposed to invert the
> exit status:
> 
> >Normally, exit status is 0 if matches were found, and 1 if no matches
> >were found (the `-v' option inverts the sense of the exit status).

> However it doesn't seem to work like that for empty input.

> I suspect this may be a documentation bug; perhaps it should say
> something like:
> 
> 'If the -v flag is given, then a "matching line" is one which does _not_
> match the pattern.  The exit status is still 0 if there were no
> "matching lines" and 1 if there were some.'

That is indeed the way it is supposed to work according to POSIX.2:

"
    -v          Select lines not matching any of the specified patterns.
...

 The grep utility shall exit with one of the following values:

     0    One or more lines were selected.

     1    No lines were selected.

    >1    An error occurred.
"

Clarifying the documentation might be in order.

-- 
Tapani Tarvainen



reply via email to

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