Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!seismo!hao!hplabs!sri-unix!greep@su-dsn From: greep@su-dsn@sri-unix.UUCP Newsgroups: net.unix Subject: "if" statement in sh with -e flag Message-ID: <5515@sri-arpa.UUCP> Date: Wed, 14-Sep-83 17:26:00 EDT Article-I.D.: sri-arpa.5515 Posted: Wed Sep 14 17:26:00 1983 Date-Received: Fri, 23-Sep-83 08:00:19 EDT Lines: 24 From: Steven Tepper The "if" statement in /bin/sh seems to be pretty useless if the shell is running with the -e flag (which says to exit on any errors, including non-zero returns from programs). The problem is that if the program called as the test returns non-zero, the shell exits instead of doing the "else" part. Of course if you know it will always return 0, then there's no point to the test. I found this when trying to use it in a makefile, since Make calls sh with -e, and there doesn't seem to be any way to "unset" the -e flag. I got around it by calling another sh (without -e), eg: newfile: sh -c \ "if cmp foo1 foo2; \ then \ echo 'File unchanged'; \ else \ set -e; \ bar; \ fi" (the "set -e" is so Make will stop if bar dies). Does anyone know of a better way to handle this?