72 echo $(( iv += (jv + 9)))
73 echo $(( (iv + 4) % 7 ))
79 # conditional expressions
80 echo $(( 4<5 ? 1 : 32))
81 echo $(( 4>5 ? 1 : 32))
82 echo $(( 4>(2+3) ? 1 : 32))
83 echo $(( 4<(2+3) ? 1 : 32))
84 echo $(( (2+2)<(2+3) ? 1 : 32))
85 echo $(( (2+2)>(2+3) ? 1 : 32))
87 # bug in bash versions through bash-3.2
89 W=$((S>99?4:S>9?3:S>0?2:0))
93 # check that the unevaluated part of the ternary operator does not do
94 # evaluation or assignment
98 echo $((1 ? 20 : (x+=2)))
100 echo $((0 ? (y+=2) : 30))
106 echo $((1 ? 20 : (x+=2)))
108 echo $((0 ? (y+=2) : 30))
111 # check precedence of assignment vs. conditional operator
116 # check precedence of assignment vs. conditional operator
118 echo $((0 ? x+=2 : 20))
120 # associativity of assignment-operator operator
121 declare -i i=1 j=2 k=3
122 echo $((i += j += k))
126 echo $(( 0x100 | 007 ))
151 # missing number after base
154 # these should generate errors
159 echo $(( jv += \$iv ))
160 let 'rv = 7 + (43 * 6'
167 ((echo abc; echo def;); echo ghi)
169 if (((4+4) + (4 + 7))); then
173 (()) # make sure the null expression works OK
176 echo $(( a[1] + a[2] ))
177 echo $(( (a[1] + a[2]) == a[3] ))
178 (( (a[1] + a[2]) == a[3] )) ; echo $?
180 # test pushing and popping the expression stack
183 echo $(( ( 4 + A ) + 4 ))
185 echo $(( ( 4 + A ) + 4 ))
187 # badly-formed conditional expressions
192 # precedence and short-circuit evaluation
196 echo $(( 0 && B=42 ))
199 echo $(( 1 || B=88 ))
202 echo $(( 0 && (B=42) ))
205 echo $(( (${$} - $$) && (B=42) ))
208 echo $(( 1 || (B=88) ))
211 # until command with (( )) command
230 # {pre,post}-{inc,dec}rement and associated errors
263 ${THIS_SH} ./arith1.sub
264 ${THIS_SH} ./arith2.sub
265 ${THIS_SH} ./arith3.sub
266 ${THIS_SH} ./arith4.sub
268 # make sure arithmetic expansion handles ints > 2**31 - 1 using intmax_t
269 echo $(( 2147483645 + 4 ))
271 # other tests using INTMAX_MIN and INTMAX_MAX that cause exceptions if not
272 # handled correctly -- problem through bash-4.2
273 ${THIS_SH} ./arith5.sub
275 # problems with suppressing evaluation present through bash-4.2
276 ${THIS_SH} ./arith6.sub
296 echo $(( 8#$(printf "%o\n" $n) ))
298 echo $(( 16#$(printf "%x\n" $n) ))
299 echo $(( 16#$(printf "%X\n" $n) ))
301 # causes longjmp botches through bash-2.05b