From owner-freebsd-hackers Thu Jun 3 13: 3:30 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from gateway.cybernet.com (gateway.cybernet.com [192.245.33.1]) by hub.freebsd.org (Postfix) with ESMTP id 8F7E71599E for ; Thu, 3 Jun 1999 13:03:28 -0700 (PDT) (envelope-from mtaylor@cybernet.com) Received: from spiffy.cybernet.com (spiffy.cybernet.com [192.245.33.55]) by gateway.cybernet.com (8.8.8/8.8.8) with ESMTP id QAA13176 for ; Thu, 3 Jun 1999 16:04:46 -0400 (EDT) (envelope-from mtaylor@cybernet.com) Message-ID: X-Mailer: XFMail 1.3 [p0] on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 8bit MIME-Version: 1.0 Date: Thu, 03 Jun 1999 16:05:03 -0400 (EDT) Reply-To: mtaylor@cybernet.com Organization: Cybernet Systems From: "Mark J. Taylor" To: freebsd-hackers@freebsd.org Subject: expr pitfall (FYI) Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Well, I found an ugly today. Nothing to do with FreeBSD, directly, just one of those pitfalls that you run into that is juicy: expr '1' : '\(.*\)' returns "1", exit status of "0" expr '0' : '\(.*\)' returns "0", exit status of "1" expr 0 + 0 returns "0", exit status of "1" Why is this an error condition (I had this in a Makefile)? The pattern did match, and the addition did succeed, but the resulting string happened to be the string "0". Well, as the man page expr(1) does indicate that if the expression is an empty string or 0, a "1" is the exit code. Nobody said I have to like it. :) I've never been aware of this behavior of expr. I thought that I'd let you in on this little "problem" before, someday, you may run into it as well. Don't go around using expr to match the string "0", or to add numbers that sum up to 0. :) -Mark Taylor NetMAX Developer mtaylor@cybernet.com To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message