InnerhalbNach weiteren Dokumenten suchenSupport-Ressourcen | Dieses Buch im PDF-Format herunterladen (6561 KB)
expr(1B)Name | Synopsis | Description | Examples | Exit Status | Attributes | See Also | Diagnostics | Bugs Name
Synopsis/usr/ucb/expr argument... Description
The expr utility evaluates expressions as specified by its arguments. After evaluation, the result is written on the standard output. Each token of the expression is a separate argument, so terms of the expression must be separated by blanks. Characters special to the shell must be escaped. Note: 0 is returned to indicate a zero value, rather than the null string. Strings containing blanks or other special characters should be quoted. Integer-valued arguments may be preceded by a unary minus sign. Internally, integers are treated as 32-bit, two's-complement numbers. The operators and keywords are listed below. Characters that need to be escaped are preceded by `\'. The list is in order of increasing precedence, with equal precedence operators grouped within { } symbols. ExamplesExample 1 Adding an integer to a shell variableAdd 1 to the shell variable a.
Example 2 Returning a path name segmentReturn the last segment of a path name (that is, the filename part). Watch out for / alone as an argument: expr will take it as the division operator (see BUGS below).
Example 3 Using // characters to simplify the expressionThe addition of the // characters eliminates any ambiguity about the division operator and simplifies the whole expression.
Example 4 Returning the value of a variableReturns the number of characters in $VAR.
Exit Status
expr returns the following exit codes: AttributesSee attributes(5) for descriptions of the following attributes:
See AlsoDiagnostics
BugsAfter argument processing by the shell, expr cannot tell the difference between an operator and an operand except by the value. If $a is an =, the command:
looks like:
as the arguments are passed to expr (and they will all be taken as the = operator). The following works:
Note: the match, substr, length, and index operators cannot themselves be used as ordinary strings. That is, the expression:
generates the `syntax error' message as shown instead of the value 1 as you might expect. Name | Synopsis | Description | Examples | Exit Status | Attributes | See Also | Diagnostics | Bugs |
||||||||||||