Double parenthesis (( ... ))
is used for arithmetic operations.
Double square brackets [[ ... ]]
can be used to compare and examine numbers (only integers are supported), with the following operators:
· NUM1 -eq NUM2 returns true if NUM1 and NUM2 are numerically equal.
· NUM1 -ne NUM2 returns true if NUM1 and NUM2 are not numerically equal.
· NUM1 -gt NUM2 returns true if NUM1 is greater than NUM2.
· NUM1 -ge NUM2 returns true if NUM1 is greater than or equal to NUM2.
· NUM1 -lt NUM2 returns true if NUM1 is less than NUM2.
· NUM1 -le NUM2 returns true if NUM1 is less than or equal to NUM2.
For example
if [[ $age > 21 ]] # bad, > is a string comparison operator
if [ $age > 21 ] # bad, > is a redirection operator
if [[ $age -gt 21 ]] # okay, but fails if $age is not numeric
if (( $age > 21 )) # best, $ on age is optional