ref: 9467aa06316d0b1baee5ece976bb539b14b5bf85 mrsh/test/arithm.sh -rw-r--r-- 1021 bytes View raw
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/sh -eu

echo "1 =" $((1))
echo "2*5 =" $((2*5))
echo "2/5 =" $((2/5))
echo "2%5 =" $((2%5))
echo "2+5 =" $((2+5))
echo "2-5 =" $((2-5))
echo "2<<5 =" $((2<<5))
echo "2>>5 =" $((2>>5))
echo "2<5 =" $((2<5))
echo "2<=5 =" $((2<=5))
echo "2>5 =" $((2>5))
echo "2>=5 =" $((2>=5))
echo "2==5 =" $((2==5))
echo "2!=5 =" $((2!=5))
echo "2&5 =" $((2&5))
echo "2^5 =" $((2^5))
echo "2|5 =" $((2|5))
echo "2&&5 =" $((2&&5))
echo "2||5 =" $((2||5))

# Associativity
echo "1+2+3 =" $((1+2+3))
echo "5-1-2 =" $((5-1-2))
echo "1+2*3 =" $((1+2*3))
echo "2*3+1 =" $((2*3+1))
echo "6/3/2 =" $((6/3/2))
# https://github.com/emersion/mrsh/issues/118
#echo "2*(3+1) =" $((2*(3+1)))
echo "2*(3+1)+1 =" $((2*(3+1)+1))
#echo "2|(1||1)" $((2|(1||1))) # 3
echo "(2|1)||1" $(((2|1)||1)) # 1
echo "2|1||1" $((2|1||1)) # 1
echo "1||1|2" $((1||1|2)) # 1

# Assignments
echo "(a=42) =" $((a=42)) "->" $a
#echo "(a+=1) =" $((a+=1)) "->" $a
#echo "(a-=4) =" $((a-=4)) "->" $a
#echo "(a*=9) =" $((a*=9)) "->" $a
#echo "(a/=3) =" $((a/=3)) "->" $a