Skip to content
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

Brackets trigger syntax error but are missed by shellcheck #2671

Open
1 of 2 tasks
roaima opened this issue Jan 24, 2023 · 1 comment
Open
1 of 2 tasks

Brackets trigger syntax error but are missed by shellcheck #2671

roaima opened this issue Jan 24, 2023 · 1 comment

Comments

@roaima
Copy link

roaima commented Jan 24, 2023

For bugs

  • Rule Id (if any, e.g. SC1000): No rule triggered
  • My shellcheck version (shellcheck --version or 'online'): online
  • I tried on shellcheck.net and verified that this is still a problem on the latest commit
  • It's not reproducible on shellcheck.net, but I think that's because it's an OS, configuration or encoding issue

Here's a snippet or screenshot that shows the problem:

#!/bin/bash                                                                                                                                                                                                   
i=4
echo '==' fitInvMass.C+("$i")

Here's what shellcheck currently says:

No issues detected!

Here's what I wanted or expected to see:

When bash executes this script I get this error,

myscript: line 3: syntax error near unexpected token `('
myscript: line 3: `echo '==' fitInvMass.C+("$i")'

The echo '==' is a placeholder for a command that a user was trying to include.

I would expect shellcheck to spot the syntax error, and maybe suggest that the string containing the (…) brackets should be double-quoted. (The original expression was fitInvMass.C+($i) and shellcheck suggested "SC2086 (info): Double quote to prevent globbing and word splitting" for the $i variable.)

@kusalananda
Copy link

This is likely due to accepting +("$i") as an extended globbing pattern. However, ShellCheck accepts the syntax even though the extglob shell option is not enabled.

I recognize that in the most general case, ShellCheck would likely have to evaluate the given shell code to figure out what shell options are set at any particular part of a script if it wants to find issues like these and that this may be too much to ask. But some form of heuristics could maybe be considered, such as an option not being mentioned anywhere in the code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants