~emersion/mrsh

ref: f1342b124da2cf87e57f70bd8f1a9c221bca47fe mrsh/test/arithm.sh -rw-r--r-- 1.1 KiB View raw
f1342b12Simon Ser shell/task/word: implement parameter minus operator 8 months ago
                                                                                
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
43
44
45
46
47
48
49
50
51
#!/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

# Variables
a=42
echo "a =" $((a))
echo "a+2 =" $((a+2))
echo "2*a-10 =" $((2*a-10))
echo "\$a =" $(($a))
echo "\$a+2 =" $(($a+2))

# Assignments
a=0
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