This implementation of
expr internally uses 64 bit representation of integers and checks for over- and underflows. It also treats / (division mark) and option '--' correctly depending upon context.
expr on other systems (including
NetBSD up to and including
NetBSD 1.5) might not be so graceful. Arithmetic results might be arbitrarily limited on such systems, most commonly to 32 bit quantities. This means such
expr can only process values between -2147483648 and +2147483647.
On other systems,
expr might also not work correctly for regular expressions where either side contains single forward slash, like this:
If this is the case, you might use // (double forward slash) to avoid confusion with the division operator:
expr "//$a" : '.*/\(.*\)'
According to IEEE Std 1003.2 (“POSIX.2”),
expr has to recognize special option '--', treat it as an end of command line options and ignore it. Some
expr implementations don't recognize it at all, others might ignore it even in cases where doing so results in syntax error. There should be same result for both following examples, but it might not always be:
Although
NetBSD expr handles both cases correctly, you should not depend on this behavior for portability reasons and avoid passing bare '--' as first argument.