Arithmetic in Bash

~$ 2+2
2+2: command not found

If you try to do 2+2 in bash chances are that 4 is not going to be the answer you get. To force bash to do some basic math you need to place it between the wildly non-intuitive $(( )) token.

That’s strange IMO but hey it is a step in the right direction

$((2+2))
4: command not found

That works

~$ echo $((2+2))
4

more details on this article

comments powered by Disqus