Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 03 Jun 1999 16:05:03 -0400 (EDT)
From:      "Mark J. Taylor" <mtaylor@cybernet.com>
To:        freebsd-hackers@freebsd.org
Subject:   expr pitfall (FYI)
Message-ID:  <XFMail.990603160503.mtaylor@cybernet.com>

next in thread | raw e-mail | index | archive | help

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.990603160503.mtaylor>