bug-grep
[Top][All Lists]
Advanced

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

Re: Exit statuses and errors messages (was Re: grep . /; echo $?)


From: Charles Levert
Subject: Re: Exit statuses and errors messages (was Re: grep . /; echo $?)
Date: Tue, 8 Nov 2005 22:12:49 -0500
User-agent: Mutt/1.4.1i

* On Tuesday 2005-11-08 at 20:40:12 -0500, Charles Levert wrote:
>       However, encouraging
>       users to use the "test $? -gt 1" (or
>       "test $? -ge 2") logic might be a good
>       thing to do for portability in any case,
>       as this is all that POSIX mandates (for
>       grep, cmp, diff, and possibly others).
> 
>       Should this be added to the docs?


Index: grep/ChangeLog
===================================================================
RCS file: /cvsroot/grep/grep/ChangeLog,v
retrieving revision 1.277
diff -u -r1.277 ChangeLog
--- grep/ChangeLog      9 Nov 2005 02:47:34 -0000       1.277
+++ grep/ChangeLog      9 Nov 2005 03:06:23 -0000
@@ -1,5 +1,12 @@
 2005-11-09  Charles Levert  <address@hidden>
 
+       * doc/grep.1, doc/grep.texi: Advise users to test for
+         "exit_status > 1" instead of "exit_status == 2" in order to
+         detect errors, for portability with other POSIX-compliant
+         implementations.
+
+2005-11-09  Charles Levert  <address@hidden>
+
        The following set of changes aims to make "egrep" and "fgrep"
        minimal executable programs for legacy applications, instead of
        shell scripts.  This "fgrep" is much smaller than "grep".
Index: grep/doc/grep.1
===================================================================
RCS file: /cvsroot/grep/grep/doc/grep.1,v
retrieving revision 1.35
diff -u -r1.35 grep.1
--- grep/doc/grep.1     8 Nov 2005 21:35:33 -0000       1.35
+++ grep/doc/grep.1     9 Nov 2005 03:06:31 -0000
@@ -832,6 +832,15 @@
 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.
 .SH BUGS
 .PP
 Email bug reports to
Index: grep/doc/grep.texi
===================================================================
RCS file: /cvsroot/grep/grep/doc/grep.texi,v
retrieving revision 1.58
diff -u -r1.58 grep.texi
--- grep/doc/grep.texi  8 Nov 2005 21:35:33 -0000       1.58
+++ grep/doc/grep.texi  9 Nov 2005 03:06:38 -0000
@@ -707,6 +707,12 @@
 But the exit status is 2 if an error occurred, unless the @option{-q} or
 @option{--quiet} or @option{--silent} option is used and a selected line
 is found.
+Note, however, that @sc{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.
 
 @node grep Programs
 @chapter @command{grep} programs




reply via email to

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