This warning is annoying:

        $ gexpr "foobarnone" : '^foo'
        gexpr: warning: unportable BRE: `^foo': using `^' as the first character
        of the basic regular expression is not portable; it is being ignored
        3

Even worse is the fact that this warning is *WRONG*.

>From the original Seventh Edition Unix manual we can see that the claim
made by GNU expr is not documented there:

       expr : expr
              The  matching  operator  compares  the string first
              argument with the regular expression  second  argu-
              ment; regular expression syntax is the same as that
              of ed(1).  The \(...\) pattern symbols can be  used
              to  select a portion of the first argument.  Other-
              wise, the matching operator yields  the  number  of
              characters matched (`0' on failure).

Examination of the original V7 (and 32V and SysIII) source for expr (or
regexp.h) also reveals that no such implicit '^' anchor implied either
-- the original code explicitly tests for a '^' anchor and the
expression is considered unanchored unless a leading '^' is explicitly
given.

I.e. modern versions of expr are *NOT* compatible with V7 (or 32V or
AT&T SysIII) and a portable script *MUST* use a '^' to explicitly anchor
the expression.

I think this change first appears in SysVr2.2, and I believe (IIRC) that
it was introduced as a side-effect of trying to use the newer "SysV"
regexp(3), and instead of fixing it they just documented it.  (I
personally still think an unanchored RE would be more useful but I
confess I've not currently any scripts that would require it, partly
because I do most of my work on NetBSD these days with its public domain
1003.2 compliant version.)

The implicit anchor is documented in AT&T SysVr2.2, Tenth Edition,
NetBSD, GNU expr, and of course IEEE POSIX 1003.2.

(The so-called rationale in the P1003.2 draft is very irrational on this
topic though -- obviously none of the committee knew, or at least spoke
up about, the true history of expr and why the so-called "broken"
implementations differed from their documentation).  What I'd like to do
is prevent GNU expr from promoting this false history too!  I do have
lots of scripts that use a '^' anchor just to be safe and portable and
the GNU expr warning is a real pain.

-- 
                                                        Greg A. Woods

+1 416 218-0098      VE3TCP      <[EMAIL PROTECTED]>      <robohack!woods>
Planix, Inc. <[EMAIL PROTECTED]>; Secrets of the Weird <[EMAIL PROTECTED]>

Reply via email to