Thread View: net.bugs.4bsd
1 messages
1 total messages
Started by Arthur David Olson
Mon, 15 Sep 1986 20:21
4.[123]BSD grep gives wrong exit status if files are missing (with fix)
Author: 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.
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads