We use Ansible onsite to replace contents in placeholders dynamically within shell script "templates". Shellcheck complains about the placeholders (marked by "{{ name }}" which is fine, but I'm unable to use the disable directive to bypass the errors generated.
Rule Id (if any, e.g. SC1000):
SC1009,SC1073,SC1072 (SC1083, SC1056, and SC1054 also fire but can be successfully bypassed)
My shellcheck version (shellcheck --version or "online"):
0.5.0
[X] I read the issue's wiki page, e.g. https://github.com/koalaman/shellcheck/wiki/SC2086
#!/bin/bash
# shellcheck disable=SC1009,SC1054,SC1073,SC1056,SC1072
{{ abcd }}
In a.sh line 4:
{{ abcd }}
^-- SC1009: The mentioned syntax error was in this brace group.
^-- SC1073: Couldn't parse this brace group. Fix to allow more checks.
In a.sh line 5:
^-- SC1072: Missing '}'. Fix any mentioned problems and try again.
No errors reported
I've played around with this a bit and it _looks_ like certain directives (SC1009,SC1072,SC1073) cannot be disabled globally (i.e. per file).
To clarify by example, this:
#!/bin/bash
# shellcheck disable=SC1009,SC1072,SC1073,SC1054,SC1083,SC1126
{{ abcd }} # shellcheck disable=SC1072
does the same as this:
#!/bin/bash
# shellcheck disable=SC1054,SC1083,SC1126
{{ abcd }} # shellcheck disable=SC1072
I'm no expert but my guess is that has to do with the fact that they all have to do with Parse Errors. I don't think they _could_ be disabled globally because ShellCheck needs to be able to parse code in order to lint it.
As ShellCheck can not work without parsing, disabling those directives would be exactly the same as simply not using ShellCheck at all...
Hello @balloonpopper and @Potherca,
this is an interesting issue and I had similar ones. My solution is to use mostly variables whenever possible. An example:
#/bin/bash
external_ip="{{ external_ip }}"
port="{{ port }}"
python -m http.server --bind "$external_ip" "$port"
While this is admittedly an oversimplified example, it works in most cases from my experience. The added benefit is, that your templated shell scripts look much cleaner and easier to grasp most of the time.
WDYT?
Thanks for your replies. In my opinion, the setting should apply globally, regardless of the file contents. I should be able to throw any type of file at it, with any contents, and as long as the global ignore rule is there, it shouldn't trigger the error. Implementing that might not end up feasible due to how shellcheck parses the file, but that is my expectation for how it should behave.
Did you find a workaround?
These days ansible is used heavily for automation, so scripts contain {{foo}}.
(And this triggers SC1083)
Most helpful comment
Hello @balloonpopper and @Potherca,
this is an interesting issue and I had similar ones. My solution is to use mostly variables whenever possible. An example:
While this is admittedly an oversimplified example, it works in most cases from my experience. The added benefit is, that your templated shell scripts look much cleaner and easier to grasp most of the time.
WDYT?