Bug 11721 - ash subshell vs. arithmetic bracket parsing issue
Summary: ash subshell vs. arithmetic bracket parsing issue
Status: RESOLVED WONTFIX
Alias: None
Product: Busybox
Classification: Unclassified
Component: Standard Compliance (show other bugs)
Version: 1.30.x
Hardware: All All
: P5 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-10 20:19 UTC by Chris Renshaw
Modified: 2019-06-27 06:43 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 Chris Renshaw 2019-03-10 20:19:02 UTC
Nesting brackets as follows in ash does not follow the standard in bash, mksh or even busybox's hush:

this=$((blah || blarg) 2>/dev/null);

To better test remove the redirect for the following command (noting the space to preserve the nesting):

this=$((blah || blarg) );

On any shell I've tested but ash this correctly gives error 127 for the commands grouped not being able to run. ash instead incorrectly interprets it as an arithmetic statement, presumably due to the $((, despite it not closing with )), and will hang awaiting )) or in a script will error out it missing the )).
Comment 1 Denys Vlasenko 2019-06-09 15:17:09 UTC
I'm actually surprised bash looks that far into the input to determine what $(( means. hush does not do that: (unless math support is disabled,) it will interpret $(( as the start of arithmetic substitution.
Comment 2 Chris Renshaw 2019-06-10 00:46:47 UTC
Hmm, odd, you're right, I seem to have been mistaken that hush treats it differently from ash. bash and mksh however definitely do seem to be able to interpret it correctly.
Comment 3 Denys Vlasenko 2019-06-11 13:16:22 UTC
It's not obvious what "correctly" is.
For example, in C syntax, the longest sequence of chars which forms a valid token is taken as next token - no lookahead. In this case, this rule would see "$((" as next token.