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
mtay...@cybernet.com



To Unsubscribe: send mail to majord...@freebsd.org
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to