Package: grep
Version: 2.5.3~dfsg-3
Severity: normal

    % man grep | grep -nA 1 "But the exit status"
    584:       otherwise.  But the exit status is 2 if an error occurred,  
unless  the
    585-       -q  or --quiet or --silent option is used and a selected line is 
found.

It's not clear what that sentence means.  Up to the comma is OK, but
what follows the conjuction "unless" is confusing.  It seems to be
saying that the '2' exit code somehow depends on the '-q' flag, or
perhaps that a '1' exit code takes precedence over a '2' exit code.

Test:

    # do a true search with a bogus option
    % echo yes | grep --fubar --quiet yes ; echo $?
    grep: unrecognized option `--fubar'
    Usage: grep [OPTION]... PATTERN [FILE]...
    Try `grep --help' for more information.
    2

Apparently the '--quiet' option combined with a found line does
NOT effect the '2' exit code.

Attached is a patch for the whole paragraph.  

Current:

       Normally,  the  exit  status  is  0  if  selected lines are found and 1
       otherwise.  But the exit status is 2 if an error occurred,  unless  the
       -q  or --quiet or --silent option is used and a selected line is found.
       Note, however, that POSIX only mandates, for  programs  such  as  grep,
       cmp, and diff, that the exit status in case of error be greater than 1;
       it is therefore advisable, for the sake of portability,  to  use  logic
       that  tests  for  this  general  condition  instead  of strict equality
       with 2.

Suggested revision (attached):

       The exit status is 0 if selected lines are found, and 1 if not found.
       If an error occurred the exit status is 2.  (Note: POSIX error handling 
       code should check for '2' or greater.)


Hope this helps...


-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.22-2-k7 (SMP w/1 CPU core)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968) (ignored: LC_ALL set to C)
Shell: /bin/sh linked to /bin/dash

Versions of packages grep depends on:
ii  libc6                         2.6.1-5    GNU C Library: Shared libraries

grep recommends no packages.

-- no debconf information

--- grep.1      2007-10-04 08:08:30.000000000 -0400
+++ /tmp/grep.1 2007-10-16 03:04:23.000000000 -0400
@@ -1157,23 +1157,9 @@
 is not set.
 .
 .SH "EXIT STATUS"
-Normally, the exit status is 0 if selected lines are found and 1 otherwise.
-But the exit status is 2 if an error occurred, unless the
-.B \-q
-or
-.B \-\^\-quiet
-or
-.B \-\^\-silent
-option is used and a selected line is found.
-Note, however, that \s-1POSIX\s0 only mandates, for programs such as
-.BR grep ,
-.BR cmp ,
-and
-.BR diff ,
-that the exit status in case of error be greater than 1;
-it is therefore advisable, for the sake of portability,
-to use logic that tests for this general condition
-instead of strict equality with\ 2.
+The exit status is 0 if selected lines are found, and 1 if not found.          
+If an error occurred the exit status is 2.  (Note: POSIX error 
+handling code should check for '2' or greater.)
 .
 .SH COPYRIGHT
 Copyright \(co

Reply via email to