rickert@mp.cs.niu.edu (Neil Rickert) (04/21/91)
In article <1991Apr21.001702.5661@umbc3.umbc.edu> rouben@math16.math.umbc.edu (Rouben Rostamian) writes: >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"? I just ran: strings /bin/expr From the output I would guess that 'match', 'index', 'substr' and 'length' are builin functions or operators for 'expr', although they are not documented in any man pages that I have seen. I don't know the syntax for using them either. I guess this is one of those questions to cross post to wizards. -- =*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*= Neil W. Rickert, Computer Science <rickert@cs.niu.edu> Northern Illinois Univ. DeKalb, IL 60115 +1-815-753-6940
henry@angel.Eng.Sun.COM (Henry McGilton) (04/21/91)
In article <1991Apr21.023416.5795@mp.cs.niu.edu>, rickert@mp.cs.niu.edu (Neil Rickert) writes: * In article <1991Apr21.001702.5661@umbc3.umbc.edu> rouben@math16.math.umbc.edu (Rouben Rostamian) writes: ** 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"? * I just ran: strings /bin/expr * From the output I would guess that 'match', 'index', 'substr' and * 'length' are builin functions or operators for 'expr', although * they are not documented in any man pages that I have seen. * I don't know the syntax for using them either. * I guess this is one of those questions to cross post to wizards. I hope not. From SunOS expr manual page (last updated 5 January 1988): ``Note: the match, substr, length, and index operators cannot themselves be used as ordinary strings.'' ........ Henry
ric@optima.UUCP (Ric Anderson) (04/21/91)
From article <1991Apr21.023416.5795@mp.cs.niu.edu>, by rickert@mp.cs.niu.edu (Neil Rickert): > In article <1991Apr21.001702.5661@umbc3.umbc.edu> rouben@math16.math.umbc.edu (Rouben Rostamian) writes: [stuff deleted] >>coincide. Now, would somebody please explain why the command: >> expr "match" : "ma" >>complains of a "syntax error"? > > I just ran: strings /bin/expr > > From the output I would guess that 'match', 'index', 'substr' and 'length' > are builin functions or operators for 'expr', although they are not documented > in any man pages that I have seen. According to the man page on my system, the syntax of these functions is : string : re match string re look in string for the regular expression "re". returns the number of characters matched, or the string matched if \(...\) is used. substr string integer-1 integer-2 return the substring of "string" starting at integer-1, of length integer-2 characters. 1 = first character, and a length greater than whats left, returns whats left. index string list return the position of the first character in "string" that occurs in "list" length string return the length of "string". Ric (ric@cs.arizona.edu <Ric Anderson>)
xtdn@levels.sait.edu.au (04/21/91)
rouben@math16.math.umbc.edu (Rouben Rostamian) writes: >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"? It is, as you suggest, because you are using a builtin command incorrectly. I forget the exact details now, but I used often to suffer from similar problems with arguments that looked like numeric expressions. Anyway, the point is that if you prefix the argument with something that makes it look like nothing special, you won't suffer this type of problem. So, for example, use: expr "xmatch" : "xma" - 1 David Newall, 16:32:56.04, Tuesday, 1991 Phone: +61 8 344 2008 "Life is uncertain: Eat dessert first" E-mail: xtdn@lux.sait.edu.au
guy@auspex.auspex.com (Guy Harris) (04/23/91)
> 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).
cliff@demon.co.uk (Cliff Stanford) (04/23/91)
In article <1991Apr21.023416.5795@mp.cs.niu.edu> rickert@mp.cs.niu.edu (Neil Rickert) writes: >In article <1991Apr21.001702.5661@umbc3.umbc.edu> rouben@math16.math.umbc.edu (Rouben Rostamian) writes: >>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"? > > I just ran: strings /bin/expr > > From the output I would guess that 'match', 'index', 'substr' and 'length' >are builin functions or operators for 'expr', although they are not documented >in any man pages that I have seen. > Well I'm blowed! All those work although I've not seen any documentation for any one of them. (SCO 3.2.2) Input Output ----- ------ expr match abcde abc 3 expr index abcde cd 3 expr length abcde 5 expr substr abcde 2 3 bcd Why doesn't anyone DOCUMENT unix? Cliff. -- Cliff Stanford Email: cliff@demon.co.uk (Work) Demon Systems Limited cms@demon.co.uk (Home) 42 Hendon Lane Phone: 081-349 0063 (Office) London N3 1TT England 0860 375870 (Mobile)
peter@ficc.ferranti.com (Peter da Silva) (04/25/91)
In article <1991Apr22.230906.9239@demon.co.uk> cliff@demon.co.uk (Cliff Stanford) writes: > Why doesn't anyone DOCUMENT unix? > Cliff. Because that would take all the FUN out of it! -- Peter da Silva. `-_-' peter@ferranti.com +1 713 274 5180. 'U` "Have you hugged your wolf today?"