In addition to the
[[ ]] compound command,
bash also provides the
(( )) compound command, which is useful for operating on integers. It supports a full set of arithmetic evaluations, a subject we will cover fully in Chapter 34.
(( )) is used to perform arithmetic truth tests. An arithmetic truth test results in true if the result of the arithmetic evaluation is non-zero.
if ((1)); then echo "It is true."; fiIt is true. [me@linuxbox ˜]$
if ((0)); then echo "It is true."; fi[me@linuxbox ˜]$
(( )), we can slightly simplify the
test-integer2 script like this:
#!/bin/bash # test-integer2a: evaluate the value of an integer. INT=-5 if [[ "$INT" =˜ ^-?[0-9]+$ ]]; then if
((INT == 0)); then echo "INT is ...