Bug 10706 - sh/ash is incorrectly parsing aritmetical expression
Summary: sh/ash is incorrectly parsing aritmetical expression
Status: RESOLVED FIXED
Alias: None
Product: Busybox
Classification: Unclassified
Component: Other (show other bugs)
Version: 1.27.x
Hardware: All Linux
: P5 minor
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-28 18:13 UTC by Petr Cvek
Modified: 2018-01-28 19:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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!