New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
((expression)) at the start of a $(expression) is miss-parsed #590
Comments
|
If that works then it's a bug in bash; it should use "longest match wins" |
|
OK, apparently it's not that simple. Later versions of Bash have some "smart matching" logic where it counts the Personally I don't think it's a good idea to rely on that;
|
|
I reported it as a bug, and it sounds like POSIX allows this behavior, though it's undefined. It might not be good syntax, but it seems like it shouldn't fail the ShellCheck parser. |
|
Yeah, this is an unfortunate ugliness inherent to shell syntax but it is valid by spec (bottom of section 2.6.3 Command Substitution though the specific quoted text is new to the 2013 edition of the spec the ambiguity is noted in the 2004 edition as well). That said counting on it working for you is a bit of a gamble since you are playing with what the shell thinks it can parse as an arithmetic expansion versus what it can't. So this should probably be a warning. |
|
Would the right thing be to warn about Or should there be matching logic similar to bash's where only |
|
Ideally I think the answer would be both. That said I also think that's problematic. Fixing the parse error would also be nice but runs into the "gamble" bit of my previous comment I think. You'd have to pick a specific sh/bash parsing behavior to emulate and if that parsing changes in sh/bash then shellcheck stops catching/matching the same cases. (Given that this is a parsing error that prevents shellcheck analysis entirely perhaps a shellcheck directive to instruct shellcheck to skip parsing of this line and pick up again afterwards would be in order? Or a pair of directives (e.g. |
|
Any Optimally this should also have handled e.g. |
For example:
This reports a "SC1073 Couldn't parse this $((..)) expression." error, but this evaluates just fine in Bash:
The text was updated successfully, but these errors were encountered: