blob: 8d791811420684198ef76f92377e52669ab6143c [file] [log] [blame]
Denys Vlasenkod84a6042021-09-25 22:04:45 +02001# ++ and -- are not inc/dec operators on non-variables, they are + + and - - sequences
Denis Vlasenko1c660b42007-03-05 00:27:50 +00002( echo $(( --7 )) )
3( echo $(( ++7 )) )
4( echo $(( -- 7 )) )
5( echo $(( ++ 7 )) )
6
7#ash# ((++array[0] ))
8#ash# echo 1 $array
9#ash# (( ++ array[0] ))
10#ash# echo 2 $array
11
12#ash# (( ++a ))
13#ash# echo 1 $a
14#ash# (( ++ a ))
15#ash# echo 2 $a
16
17#ash# (( --a ))
18#ash# echo 1 $a
19#ash# (( -- a ))
20#ash# echo 0 $a
21 a=0
22
23echo 5 $(( 4 + ++a ))
24echo 1 $a
25
Denys Vlasenkof19e3c12018-01-28 20:13:33 +010026# this is treated as 4 + ++a
27echo 6 $(( 4+++a ))
28echo 2 $a
Denis Vlasenko1c660b42007-03-05 00:27:50 +000029 a=2
30
Denys Vlasenkof19e3c12018-01-28 20:13:33 +010031# this is treated as 4 - --a
32echo 3 $(( 4---a ))
33echo 1 $a
Denis Vlasenko1c660b42007-03-05 00:27:50 +000034 a=1
35
36echo 4 $(( 4 - -- a ))
37echo 0 $a
38
39#ash# (( -- ))
Denys Vlasenkod84a6042021-09-25 22:04:45 +020040# -- is not a dec operator on non-variable, it is the - - sequence
41echo $(( ---7 ))
Denis Vlasenko1c660b42007-03-05 00:27:50 +000042( echo $(( -- - 7 )) )
43
44#ash# (( ++ ))
Denys Vlasenkod84a6042021-09-25 22:04:45 +020045# ++ is not a inc operator on non-variable, it is the + + sequence
46echo $(( ++7 ))
Denis Vlasenko1c660b42007-03-05 00:27:50 +000047( echo $(( ++ + 7 )) )
48
Denys Vlasenko62e43312021-09-25 22:25:19 +020049echo -7 $(( ++-7 ))
50echo -7 $(( ++ - 7 ))
Denis Vlasenko1c660b42007-03-05 00:27:50 +000051
Denys Vlasenko62e43312021-09-25 22:25:19 +020052echo 7 $(( +--7 ))
53echo 7 $(( -- + 7 ))