Standard arithmetic tests

Another advantage that we can gain from these double parentheses is with the tests. Rather than having to use -gt for greater than, we can simply use >. We can demonstrate this in the following code:

$(( COUNT > 1 )) && echo "Count is greater than 1"

The following screenshot demonstrates this:

It is this standardization, both in the C-style manipulation and tests, that makes the double parenthesis so useful to us. This use extends to both the command line and scripts. We will use this feature extensively when we look at looping constructs.

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.