Would sombody please explain? (SUMMARY)

Rouben Rostamian rouben at math9.math.umbc.edu
Mon Apr 22 00:36:49 AEST 1991


In an earlier article I asked:

> The command:
>     expr "Match" : "Ma"
> returns 2, as it should, since the first two characters of "Match" and "Ma"
> coincide.  Now, would somebody please explain why the command:
>     expr "match" : "ma"
> complains of a "syntax error"?
> 
> This happens on DEC ultrix (both in sh and csh,) on SUNs, and on Stardent.

As many have pointed out, "match" is a reserved keyword in the expr(1)
utility.  Strangely enough, it is not documented in the man pages of
the two systems I had checked (DEC RISC ultrix and Stardent.)

The documentation can be found on some (all?) SUN machines.
For the benefit of those who do not have a complete documentation
of expr, I have appended the missing parts at the end of this message.

Thanks to all who responded.

Rouben Rostamian

--
Rouben Rostamian                          Telephone: (301) 455-2458
Department of Mathematics and Statistics  e-mail:
University of Maryland Baltimore County   bitnet: rostamian at umbc.bitnet
Baltimore, MD 21228,  U.S.A.              internet: rouben at math9.math.umbc.edu
------------------------------------------------------------------------------
Sun Release 4.0    Last change: 5 January 1988                  1

     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.

     ( expr )
          Parentheses may be used for grouping.
--



More information about the Comp.unix.questions mailing list