45.29 Testing Characters in a String with expr
The
expr
(
45.28
)
command does a lot of different things with expressions.
One expression it handles has three arguments: first, a string; second,
a colon (
expr
can count the number of characters that match the
regular expression.
The regular expression is automatically anchored to the
start of the string you're matching, as if you'd typed a
$ When a regular expression matches some character(s), expr returns a zero ("true") exit status ( 44.7 ) . If you want a true/false test like this, throw away the number that expr prints and test its exit status:
- |
|