4.[123]BSD grep gives wrong exit status if files are missing (with fix)
Arthur David Olson
ado at elsie.UUCP
Tue Sep 16 06:21:47 AEST 1986
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 at seismo.ARPA
DEC, VAX, Elsie & Ado are Digital, Borden & Ampex trademarks.
More information about the Comp.bugs.4bsd.ucb-fixes
mailing list