Article View: net.bugs.4bsd
Article #16744.[123]BSD grep gives wrong exit status if files are missing (with fix)
From: Arthur David Olson
Date: Mon, 15 Sep 1986 20:21
Date: Mon, 15 Sep 1986 20:21
68 lines
2275 bytes
2275 bytes
Index: bin/grep Fix
Description:
The manual page for "grep" says that "Exit status is 0 if any matches
are found, 1 if none, 2 for syntax errors or inaccessible files."
But neither non-existent files nor files that cannot be successfully
read yield an exit status of 2.
Repeat-By:
Script started on Mon Sep 15 16:13:04 1986
Warning: no access to tty; thus no job control in this shell...
% /bin/grep exit frobozz /bin/false
grep: can't open frobozz
% echo $status
2
% /usr/ucb/grep exit frobozz /bin/false
Can't open frobozz
/bin/false:exit 1
% echo $status
0
%
script done on Mon Sep 15 16:13:39 1986
Fix:
Either change the manual page or change grep's performance.
Here are the changes to the function "execute" in the file "ucbgrep.c"
for 4.1BSD systems; later versions of BSD require similar changes in
different files. As usual, the additions are conditioned on
"OLDVERSION".
> . . .
> execute(file)
> {
> register char *p1, *p2;
> register c;
> int f;
> char *ebp, *cbp;
>
> if (file) {
> if ((f = open(file, 0)) < 0) {
> fprintf(stderr, "Can't open %s\n", file);
> #ifndef OLDVERSION
> exit(2);
> #endif /* !OLDVERSION */
> }
> } else
> f = 0;
> . . .
> if ((c = read(f, ibuf, BUFSIZ)) <= 0) {
> close(f);
> #ifndef OLDVERSION
> if (c < 0) {
> (void) fprintf(stderr,
> "Error reading %s\n",
> (file == 0) ?
> "standard input" :
> file);
> exit(2);
> }
> #endif /* !OLDVERSION */
> if (cflag) {
> if (lflag) {
> . . .
--
Bug/s is a Volkswagen/Warner Brothers trademark.
--
UUCP: ..decvax!seismo!elsie!ado ARPA: elsie!ado@seismo.ARPA
DEC, VAX, Elsie & Ado are Digital, Borden & Ampex trademarks.
Technical Details
Message-ID:
<6241@elsie.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!seismo!elsie!adoShow Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: arc1-ca.pugleaf.net!utzoo!mnetor!seismo!elsie!ado From: ado@elsie.UUCP (Arthur David Olson) Newsgroups: net.bugs.4bsd Subject: 4.[123]BSD grep gives wrong exit status if files are missing (with fix) Message-ID: <6241@elsie.UUCP> Date: Mon, 15-Sep-86 16:21:47 EDT Article-I.D.: elsie.6241 Posted: Mon Sep 15 16:21:47 1986 Date-Received: Mon, 15-Sep-86 21:17:47 EDT Organization: NIH-LEC, Bethesda, MD Lines: 68 Keywords: grep exit