Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!decvax!wivax!linus!philabs!cmcl2!floyd!trb From: trb@floyd.UUCP Newsgroups: net.unix-wizards Subject: egrep bug Message-ID: <1546@floyd.UUCP> Date: Fri, 27-May-83 15:36:15 EDT Article-I.D.: floyd.1546 Posted: Fri May 27 15:36:15 1983 Date-Received: Sun, 29-May-83 06:54:10 EDT Lines: 37 In 4.1bsd, when egrep comes upon a file (to be searched) which it can't open it immediately exits (2) even though there are more files to be searched. This is inconsistent with the behavior of grep and fgrep and it's also inconvenient. If I'm searching through *.c and one of the files happens to be unreadable, I don't want egrep to stop. The fix for that is easy, just change the exit(2) in the error code after the open (in function execute()) to a return. Problem is, *grep exits with one of the following codes: 0 - found a match 1 - found no match 2 - syntax errors or inaccessible files. Notice that it's quite possible to find a match and also have inaccessible files. I suppose you can return a 2 in that case. I don't know whose job it is to care for the grep family, but I don't know whether they want to put a flag in egrep or what, because they previously considered inaccessible files fatal. I think that's ridiculous, but I don't want to break someone's shell script. Right now, egrep exits all over the place with hard coded values, never based upon a previous state, except for the "found a match" flag, which looks like this exit(nsucc == 0); which I consider pretty baroque. I hacked my egrep so that if it can't open a file it sets a new flag cantopen=2; and returns instead of exiting. Then, right before the aforementioned exit(nsucc == 0); (at the end of main()) if(cantopen == 2) exit(2); This seems right to me, but it will change the behavior of egrep in a semi-documented way. Andy Tannenbaum Bell Labs Whippany, NJ (201) 386-6491