Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2 -fstack-protector-strong -Wformat
-Werror=format-security -Wall
uname output: Linux delphux 6.12.27+bpo-amd64 #1 SMP PREEMPT_DYNAMIC Debian
6.12.27-1~bpo12+1 (2025-05-19) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.2
Patch Level: 15
Release Status: release

Description:
        The shorthands "++", "--", "+=1" and "-=1" in bash arithmetic
erroneously return exit code 1 when a variable is either incremented by
"++" or decremented by "--" from 0 or incremented by "+=1" or decremented
by "-=1" from -1 and 1 respectively, although the variable value changes
properly.


Repeat-By:

Runing the following line, demonstrates the "++" behaviour at 0:
A=-3; while [[ $A -le 3 ]]; do echo -ne "$A\t"; ((A++)); echo $?; done
-3      0
-2      0
-1      0
0       1
1       0
2       0
3       0

Runing the following line, demonstrates the "--" behaviour at 0:
A=3; while [[ $A -ge -3 ]]; do echo -ne "$A\t"; ((A--)); echo $?; done
3       0
2       0
1       0
0       1
-1      0
-2      0
-3      0

Runing the following line, demonstrates the "+=1" behaviour at -1:
A=-3; while [[ $A -le 3 ]]; do echo -ne "$A\t"; ((A+=1)); echo $?; done
-3      0
-2      0
-1      1
0       0
1       0
2       0
3       0

Runing the following line, demonstrates the "-=1" behaviour at 1:
A=3; while [[ $A -ge -3 ]]; do echo -ne "$A\t"; ((A-=1)); echo $?; done
3       0
2       0
1       1
0       0
-1      0
-2      0
-3      0

Sincerely,
Stamatis Mavrogeorgis

Reply via email to