version 1.31.4.1, 2012/05/23 10:07:04 |
version 1.31.4.2, 2012/10/30 18:46:06 |
Line 145 an error occurred (such as memory alloca |
|
Line 145 an error occurred (such as memory alloca |
|
.Sh EXAMPLES |
.Sh EXAMPLES |
.Bl -enum |
.Bl -enum |
.It |
.It |
The following example adds one to the variable a. |
The following example adds one to variable |
|
.Dq a : |
.Dl a=`expr $a + 1` |
.Dl a=`expr $a + 1` |
.It |
.It |
The following example returns zero, due to subtraction having higher precedence |
The following example returns zero, due to subtraction having higher precedence |
than '\*[Am]' operator. |
than the |
|
.Dq \*[Am] |
|
operator: |
.Dl expr 1 '\*[Am]' 1 - 1 |
.Dl expr 1 '\*[Am]' 1 - 1 |
.It |
.It |
The following example returns the filename portion of a pathname stored |
The following example returns the filename portion of a pathname stored |
in variable a. |
in variable |
|
.Dq a : |
.Dl expr "/$a" Li : '.*/\e(.*\e)' |
.Dl expr "/$a" Li : '.*/\e(.*\e)' |
.It |
.It |
The following example returns the number of characters in variable a. |
The following example returns the number of characters in variable |
|
.Dq a : |
.Dl expr $a Li : '.*' |
.Dl expr $a Li : '.*' |
.El |
.El |
.Sh COMPATIBILITY |
.Sh COMPATIBILITY |
Line 164 This implementation of |
|
Line 169 This implementation of |
|
.Nm |
.Nm |
internally uses 64 bit representation of integers and checks for |
internally uses 64 bit representation of integers and checks for |
over- and underflows. |
over- and underflows. |
It also treats / (division mark) and |
It also treats |
option '--' correctly depending upon context. |
.Dq / |
|
(the division mark) and option |
|
.Dq -- |
|
correctly depending upon context. |
.Pp |
.Pp |
.Nm |
.Nm |
on other systems (including |
on other systems (including |
Line 182 can only process values between -2147483 |
|
Line 190 can only process values between -2147483 |
|
On other systems, |
On other systems, |
.Nm |
.Nm |
might also not work correctly for regular expressions where |
might also not work correctly for regular expressions where |
either side contains single forward slash, like this: |
either side contains |
|
.Dq / |
|
(a single forward slash), like this: |
.Bd -literal -offset indent |
.Bd -literal -offset indent |
expr / : '.*/\e(.*\e)' |
expr / : '.*/\e(.*\e)' |
.Ed |
.Ed |
.Pp |
.Pp |
If this is the case, you might use // (double forward slash) |
If this is the case, you might use |
|
.Dq // |
|
(a double forward slash) |
to avoid confusion with the division operator: |
to avoid confusion with the division operator: |
.Bd -literal -offset indent |
.Bd -literal -offset indent |
expr "//$a" : '.*/\e(.*\e)' |
expr "//$a" : '.*/\e(.*\e)' |
Line 196 expr "//$a" : '.*/\e(.*\e)' |
|
Line 208 expr "//$a" : '.*/\e(.*\e)' |
|
According to |
According to |
.St -p1003.2 , |
.St -p1003.2 , |
.Nm |
.Nm |
has to recognize special option '--', treat it as an end of command |
has to recognize special option |
line options and ignore it. |
.Dq -- , |
|
treat it as a delimiter to mark the end of command |
|
line options, and ignore it. |
Some |
Some |
.Nm |
.Nm |
implementations don't recognize it at all, others |
implementations don't recognize it at all; others |
might ignore it even in cases where doing so results in syntax |
might ignore it even in cases where doing so results in syntax |
error. |
error. |
There should be same result for both following examples, |
There should be same result for both following examples, |
|
|
.Nx |
.Nx |
.Nm |
.Nm |
handles both cases correctly, you should not depend on this behavior |
handles both cases correctly, you should not depend on this behavior |
for portability reasons and avoid passing bare '--' as first |
for portability reasons and avoid passing a bare |
|
.Dq -- |
|
as the first |
argument. |
argument. |
.Sh STANDARDS |
.Sh STANDARDS |
The |
The |