Some time ago, when you wanted to have any comparisons, you used the program "test", which was usually symbolic to mean "[".
So, you had expressions such as:
if [ ..... ]; then
Test
by default it is asciibetically compared, and if you need to do a numerical comparison, you need to use -lt / -gt and the like.
Then bash got its own internal test engine. To use it, you use [[.
So the same syntax you had before:
if [ ... ]; then
can be rewritten as:
if [[ ... ]]; then
and do the same, except that the comparison was done in bash itself and the fork / exec test program was not required.
Since now it does not call an external program, it is easier to add another method of comparison numerically. From here (()) appeared.
It has certain advantages, but it is usually overlooked that it imposes a numerical context.
This means you might have something like:
i=1 (( i++ )) echo $i
In short, this is not a big deal for comparisons. but it pays to learn more about (()) and [[]] in man bash.
user80168
source share