Bug 10706

Summary: sh/ash is incorrectly parsing aritmetical expression
Product: Busybox Reporter: Petr Cvek <petrcvekcz>
Component: OtherAssignee: unassigned
Status: RESOLVED FIXED    
Severity: minor CC: busybox-cvs
Priority: P5    
Version: 1.27.x   
Target Milestone: ---   
Hardware: All   
OS: Linux   
Host: Target:
Build:

Description Petr Cvek 2018-01-28 18:13:37 UTC
My script keeps crashing in Busybox 1.27.2, so after some debugging I've discovered this behaviour:

# sh
# XXX=-1
# echo $((0-$XXX))
sh: arithmetic syntax error
# echo $((0- $XXX))
1

In GNU bash 4.4.12(1)-release the same code works:

# sh
# XXX=-1
# echo $((0-$XXX))
1
# echo $((0- $XXX))
1

It seems to be general for expressions even without variables like $((0--1)) with those results:

# echo $((0--1))
-sh: arithmetic syntax error
# echo $((0-+1))
-1
# echo $((0+-1))
-1
# echo $((0++1))
-sh: arithmetic syntax error
Comment 1 Denys Vlasenko 2018-01-28 19:15:13 UTC
Fixed in git, thanks!