>From 69fa2ecde962b3469effccfa630ad346fcad367d Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 7 Oct 2014 08:23:21 -0700 Subject: [PATCH 1/2] doc: clarify exit status MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reported by Santiago Ruano Rincón in: http://bugs.gnu.org/18651 * doc/grep.in.1 (EXIT STATUS): * doc/grep.texi (Exit Status): Clarify. --- doc/grep.in.1 | 16 ++++------------ doc/grep.texi | 17 ++++++----------- 2 files changed, 10 insertions(+), 23 deletions(-) diff --git a/doc/grep.in.1 b/doc/grep.in.1 index 00d030a..16b94b2 100644 --- a/doc/grep.in.1 +++ b/doc/grep.in.1 @@ -1143,23 +1143,15 @@ when 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 +Normally the exit status is 0 if a line is selected, 1 if no lines +were selected, and 2 if an error occurred. However, if 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. +is used and a line is selected, the exit status is 0 even if an error +occurred. . .SH COPYRIGHT Copyright 1998-2000, 2002, 2005-2014 Free Software Foundation, Inc. diff --git a/doc/grep.texi b/doc/grep.texi index d7adcad..da9a1be 100644 --- a/doc/grep.texi +++ b/doc/grep.texi @@ -1025,17 +1025,12 @@ and only when @env{POSIXLY_CORRECT} is not set. @cindex exit status @cindex return 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 @option{-q} or address@hidden or @option{--silent} option is used and a selected line -is found. -Note, however, that POSIX only mandates, -for programs such as @command{grep}, @command{cmp}, and @command{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. - +Normally the exit status is 0 if a line is selected, 1 if no lines +were selected, and 2 if an error occurred. However, if the address@hidden or @option{--quiet} or @option{--silent} option is used +and a line is selected, the exit status is 0 even if an error +occurred. Other @command{grep} implementations may exit with status +greater than 2 on error. @node grep Programs @section @command{grep} Programs -- 1.9.3