March 2002
Beginner
504 pages
10h 47m
English
The expr command can be used to perform simple integer arithmetic. The general syntax of an expr command is
expr int1 op int2
Here, int1 and int2 are integers and op is one of the operators given in Table 18.3. The spaces separating op from int1 and int2 are required.
| Operand | Description |
|---|---|
| + | Addition |
| - | Subtraction |
| \* | Multiplication |
| / | Integer division (any fraction in the result is dropped) |
| % | Remainder from a division operation (also called the modulus function) |
Let's look at a few examples that illustrate the use of expr. The first example illustrates multiplication:
$ expr 3 \* 5 15
Notice that the * sign must be escaped in order to prevent the shell from viewing it as a filename expansion meta-character. ...
Read now
Unlock full access