-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Regarding shell scripts that are only meant to be source (SC2148) #581
Comments
why dont you just include the shebang? it also solves the syntax highlightning for your $EDITOR 8-) |
I just write: #!/module/for/bash |
I agree with @chauncey-garrett, having the directive would be useful. The editor highlithing issue is already handled in a similar way with:
So having a directive like |
@kurahaupo: While highly unlikely to be exploited, using |
To create even a potential vulnerability, one would also need execute Nobody would be silly enough to use 'chmod +x' on a module... ahem And as security flaws go, it's nothing beside |
I would be in favour of having another pragma syntax to indicate the shell flavour. Adding a shebang is a signal that the script is executable even if the file doesn't have the executable bit. Right now as a workaround I use |
@kurahaupo Agreed. @zimbatm That's the best alternative I've come across. Adds SC2148 as a keyword. |
This is a recurring question, and n 944313c, you can use a
Any directives specified after (or instead of) the shebang will also apply to the entire script. Using a |
@koalaman shellcheck.net as well as the latest version on |
@brother ah, That doesn't cover the homebrew formula, however :-( |
0.4.4 was pushed last week and it appears that @dunn has graciously updated the homebrew formula (thanks!). Please give it another go. |
@koalaman now with a file that has |
Also!
|
@koalaman any update on this? |
In 0.4.4 the statement works, but falsely produces that warning. It was fixed in July in 42f7479, but is not yet part of a stable release. I'm hoping to push 0.4.5 in the next 2-3 weeks. |
Thank you. |
@koalaman A 0.4.5 release would be great, so sourced files can be shellchecked as part of our CI. Thank you! |
These aren't directly executable and shellcheck will soon be pacifiable with a custom directive: koalaman/shellcheck#581
- This switches to use `# shellcheck shell=bash`, as per [this comment](koalaman/shellcheck#581 (comment)), otherwise we get errors in newer versions of shellcheck while using the `# shellcheck disable=SC2148` directive: ``` In terraform/userdata/10-db-admin line 1: ^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang. ```
- This switches to use `# shellcheck shell=bash`, as per [this comment](koalaman/shellcheck#581 (comment)), otherwise we get errors in newer versions of shellcheck while using the `# shellcheck disable=SC2148` directive: ``` In terraform/userdata/10-db-admin line 1: ^-- SC2148: Tips depend on target shell and yours is unknown. Add a shebang. ```
#!/usr/bin/env -S echo "This should not be ran directly - try using the following command: \nsource"
# shellcheck shell=sh Preamble for anyone looking for a somewhat nice solution to this problem - this wont execute if you run it directly, and prints a helpful message, but will still source if you source it. |
@Jackaed excellent idea! Small nit pick on English grammar: "run" is an (extremely) irregular verb that has "ran" as its simple past tense but "run" as its past participle; so I (and many other readers) would prefer:
rather than:
|
Shellcheck
looks to the shebang statement at the beginning of a shell script as one means of determining what language is used. This works well for shell scripts that are meant to be called as an executable.However, there are non-executable shell files where the convention is to not include the shebang statement in the file because they are meant to be sourced either by the shell during startup (e.g.,
bashrc
) or because they are part of a shell library.These files would benefit from
spellcheck
but can't be used as they are without including a shebang statement.I'd like to propose a directive for this specific case that can specify the language. Something like:
There are other related issues that have brought up this issue but the suggestions were to fall back to
sh
#215 or ignore the issue #237. I think it'd be best to allow your users the ability to specify the language type to take advantage of language specific features.I recognize that
shellcheck -s dialect
exists but this doesn't help in the case ofvim
'ssyntastic
plugin.Finally, the lang directive should throw a warning if a shebang is used simultaneously.
Alternatively, the shebang statement could simply be added to these files but I hesitate here because this is not the convention for source files.
Thoughts?
The text was updated successfully, but these errors were encountered: