1 # This program is free software: you can redistribute it and/or modify
2 # it under the terms of the GNU General Public License as published by
3 # the Free Software Foundation, either version 3 of the License, or
4 # (at your option) any later version.
6 # This program is distributed in the hope that it will be useful,
7 # but WITHOUT ANY WARRANTY; without even the implied warranty of
8 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 # GNU General Public License for more details.
11 # You should have received a copy of the GNU General Public License
12 # along with this program. If not, see <http://www.gnu.org/licenses/>.
85 echo $(( iv += (jv + 9)))
86 echo $(( (iv + 4) % 7 ))
92 # conditional expressions
93 echo $(( 4<5 ? 1 : 32))
94 echo $(( 4>5 ? 1 : 32))
95 echo $(( 4>(2+3) ? 1 : 32))
96 echo $(( 4<(2+3) ? 1 : 32))
97 echo $(( (2+2)<(2+3) ? 1 : 32))
98 echo $(( (2+2)>(2+3) ? 1 : 32))
100 # bug in bush versions through bush-3.2
102 W=$((S>99?4:S>9?3:S>0?2:0))
106 # check that the unevaluated part of the ternary operator does not do
107 # evaluation or assignment
111 echo $((1 ? 20 : (x+=2)))
113 echo $((0 ? (y+=2) : 30))
119 echo $((1 ? 20 : (x+=2)))
121 echo $((0 ? (y+=2) : 30))
124 # check precedence of assignment vs. conditional operator
129 # check precedence of assignment vs. conditional operator
131 echo $((0 ? x+=2 : 20))
133 # associativity of assignment-operator operator
134 declare -i i=1 j=2 k=3
135 echo $((i += j += k))
139 echo $(( 0x100 | 007 ))
164 # missing number after base now generates an error
167 # these should generate errors
172 echo $(( jv += \$iv ))
173 let 'rv = 7 + (43 * 6'
180 ((echo abc; echo def;); echo ghi)
182 if (((4+4) + (4 + 7))); then
186 (()) # make sure the null expression works OK
189 echo $(( a[1] + a[2] ))
190 echo $(( (a[1] + a[2]) == a[3] ))
191 (( (a[1] + a[2]) == a[3] )) ; echo $?
193 # test pushing and popping the expression stack
196 echo $(( ( 4 + A ) + 4 ))
198 echo $(( ( 4 + A ) + 4 ))
200 # badly-formed conditional expressions
205 # precedence and short-circuit evaluation
209 echo $(( 0 && B=42 ))
212 echo $(( 1 || B=88 ))
215 echo $(( 0 && (B=42) ))
218 echo $(( (${$} - $$) && (B=42) ))
221 echo $(( 1 || (B=88) ))
224 # until command with (( )) command
243 # {pre,post}-{inc,dec}rement and associated errors
276 # combinations of expansions
277 echo $(( "`echo 1+1`" ))
278 echo $(( `echo 1+1` ))
280 ${THIS_SH} ./arith1.sub
281 ${THIS_SH} ./arith2.sub
282 ${THIS_SH} ./arith3.sub
283 ${THIS_SH} ./arith4.sub
285 # make sure arithmetic expansion handles ints > 2**31 - 1 using intmax_t
286 echo $(( 2147483645 + 4 ))
288 # other tests using INTMAX_MIN and INTMAX_MAX that cause exceptions if not
289 # handled correctly -- problem through bush-4.2
290 ${THIS_SH} ./arith5.sub
292 # problems with suppressing evaluation present through bush-4.2
293 ${THIS_SH} ./arith6.sub
295 # problems with parsing arithmetic expressions containing colons that are
296 # part of word expansions such as substring extraction
297 ${THIS_SH} ./arith7.sub
299 # problems with evaluation of conditional expressions
300 ${THIS_SH} ./arith8.sub
320 echo $(( 8#$(printf "%o\n" $n) ))
322 echo $(( 16#$(printf "%x\n" $n) ))
323 echo $(( 16#$(printf "%X\n" $n) ))
330 # causes longjmp botches through bush-2.05b