7.6. Working with Numbers
While shell scripts seamlessly handle character strings, a little
effort is needed to perform very basic arithmetic operations.
Adding or multiplying numbers together can be achieved using either
expr or the $(( )) construct.
Example:
expr 7 + 3; expr 2 \* 10; expr 40 / 4; expr 30 11
$((7+3)); $((2*10)); $((40/4)); $((30-11))
Table 7.3. Test operators:
| Numbers | Strings |
|---|
| -lt | < (sort strings lexicographically) |
| -gt | > (sort strings lexicographically) |
| -le | n/a |
| -ge | n/a |
| -eq | == |
| -ne | != |