KSH substring function (is it on your system?)
Guy Harris
guy at sun.uucp
Mon Nov 18 06:20:30 AEST 1985
> > As long as we're talking about 'substring', 'expr' has a 'substr' option
> > that used to be documented in V6.
> > ...
> > 'expr' also has 'match', 'lentgh', and 'index' options that are not
> > documented any longer. Anyone knows why?
>
> The ":" operator of expr now handles all of these cases (I've never
> heard of "index"; what does it do?):
V6? *V6?* I don't remember any "expr" command in V6; the main use of
"expr" is between backquotes in the shell, and the V6 shell didn't have
backquotes (alas). V7's "expr" had them, as did S3's; neither documented
them. They disappeared in S5; the reason is, to quote Sun's manual page for
"expr" which *does* document them:
BUGS
Note that the "match", "substr", "length", and "index"
operators cannot themselves be used as ordinary strings.
That is, the expression:
tutorial% expr index expurgatorious length
syntax error
tutorial%
generates the 'syntax error' message as shown instead of
the value 1 as you might expect.
("tutorial%" is a shell prompt in the above example).
"index" is documented there as:
index "string" "character-list"
reports the first position in "string" at which any one
of the characters in "character-list" matches a character
in "string".
Note that, just like the V7/4.xBSD "index" function, this is *not* the same
as the PL/I "index" function. (One reason why I approve of the renaming of
"index" to "strchr" in S3/S5.)
> -- old -- -- new --
> expr match string regexp expr string : regexp
> ...
"old" and "new" are somewhat misnomers here; all versions of "expr" since
V7's support the "new" method as well as the "old" one.
Guy Harris
More information about the Comp.unix
mailing list