1 #!/usr/bin/env bash
2
3 #### (( )) result
4 (( 1 )) && echo True
5 (( 0 )) || echo False
6 ## stdout-json: "True\nFalse\n"
7
8 #### negative number is true
9 (( -1 )) && echo True
10 ## stdout: True
11
12 #### (( )) in if statement
13 if (( 3 > 2)); then
14 echo True
15 fi
16 ## stdout: True
17
18 #### (( ))
19 # What is the difference with this and let? One difference: spaces are allowed.
20 (( x = 1 ))
21 (( y = x + 2 ))
22 echo $x $y
23 ## stdout: 1 3
24
25 #### (( )) with arrays
26 a=(4 5 6)
27 (( sum = a[0] + a[1] + a[2] ))
28 echo $sum
29 ## stdout: 15
30 ## OK zsh stdout: 9
31
32 #### (( )) with error
33 (( a = 0 )) || echo false
34 (( b = 1 )) && echo true
35 (( c = -1 )) && echo true
36 echo $((a + b + c))
37 ## stdout-json: "false\ntrue\ntrue\n0\n"