1 ## compare_shells: bash dash mksh zsh
2 ## oils_failures_allowed: 3
3
4 # Various tests for dynamic parsing of arithmetic substitutions.
5
6 #### Double quotes
7 echo $(( "1 + 2" * 3 ))
8 echo $(( "1+2" * 3 ))
9 ## STDOUT:
10 7
11 7
12 ## END
13
14 ## N-I dash status: 2
15 ## N-I dash STDOUT:
16 ## END
17
18 ## N-I mksh status: 1
19 ## N-I mksh STDOUT:
20 ## END
21
22 ## N-I zsh status: 1
23 ## N-I zsh STDOUT:
24 ## END
25
26 #### Single quotes
27 echo $(( '1' + '2' * 3 ))
28 echo status=$?
29
30 echo $(( '1 + 2' * 3 ))
31 echo status=$?
32 ## STDOUT:
33 status=1
34 status=1
35 ## END
36
37 ## N-I dash status: 2
38 ## N-I dash STDOUT:
39 ## END
40
41 ## BUG mksh status: 1
42 ## BUG mksh STDOUT:
43 199
44 status=0
45 ## END
46
47 ## N-I zsh status: 1
48 ## N-I zsh STDOUT:
49 ## END
50
51 #### Substitutions
52 x='1 + 2'
53 echo $(( $x * 3 ))
54 echo $(( "$x" * 3 ))
55 ## STDOUT:
56 7
57 7
58 ## END
59
60 ## N-I dash status: 2
61 ## N-I dash STDOUT:
62 7
63 ## END
64
65 ## N-I mksh status: 1
66 ## N-I mksh STDOUT:
67 7
68 ## END
69
70 ## N-I zsh status: 1
71 ## N-I zsh STDOUT:
72 7
73 ## END
74
75 #### Variable references
76 x='1'
77 echo $(( x + 2 * 3 ))
78 echo status=$?
79
80 # Expression like values are evaluated first (this is unlike double quotes)
81 x='1 + 2'
82 echo $(( x * 3 ))
83 echo status=$?
84 ## STDOUT:
85 7
86 status=0
87 9
88 status=0
89 ## END
90
91 ## N-I dash status: 2
92 ## N-I dash STDOUT:
93 7
94 status=0
95 ## END