Would somebody please explain?

Guy Harris guy at auspex.auspex.com
Tue Apr 23 04:05:00 AEST 1991


>  From the output I would guess that 'match', 'index', 'substr' and 'length'
>are builin functions or operators for 'expr',

They are.

>although they are not documented in any man pages that I have seen.

The original V7 "expr" had all of 'em built in.  The SunOS 4.0.3 manual
page documents them:

     string : regular-expression
     match string regular-expression
          The two  forms  of  the  matching  operator  above  are
          synonymous.  The matching operators : and match compare
          the first argument with the second argument which  must
          be  a regular expression.  Regular expression syntax is
          the same as that of ed(1), except that all patterns are
          anchored  (treated  as  if  they  begin  with  ^)  and,
          therefore, ^ is not a special character, in  that  con-
          text.   Normally,  the  matching  operator  returns the
          number of characters matched (0 on failure).   Alterna-
          tively,  the  \(...\)  pattern  symbols  can be used to
          return a portion of the first argument.

     substr string integer-1 integer-2
          Extract the subtring of  string  starting  at  position
          integer-1  and  of  length  integer-2  characters.   If
          integer-1 has  a  value  greater  than  the  length  of
          string,  expr  returns  a  null  string.  If you try to
          extract more characters than there are in string,  expr
          returns  all  the  remaining  characters  from  string.
          Beware of using negative values for either integer-1 or
          integer-2 as expr tends to run forever in these cases.

     index string character-list
          Report the first position in string at which any one of
          the characters in character-list matches a character in
          string.

     length string
          Return the length (that is, the number  of  characters)
          of string.

The S5 version ripped "substr", "index", and "length" out - probably to
avoid the problem reported in the original posting - but kept "match" as
an alias for ":", for reasons not obvious to me (considering that doing
so means that the problem reported in the original posting is *NOT*
avoided).



More information about the Comp.unix.wizards mailing list