New Rule: Executables must start with `#!/bin/bash` and a minimum number of flags.
stdedos opened this issue · comments
Stavros Ntentos commented
For bugs
- Rule Id (if any, e.g. SC1000):
- My shellcheck version (
shellcheck --version
or "online"): - The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
For new checks and feature suggestions
- https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this
- I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related
Here's a snippet or screenshot that shows the problem:
#!/bin/bash -eu
#!/usr/bin/env bash -x
# This script violates best practices by specifying options directly in the shebang line.
# The -e option causes the script to exit immediately if a command exits with a non-zero status.
# The -u option causes the script to exit if an attempt is made to use an uninitialized variable.
echo "This script has bash options in the shebang, which is not recommended."
Here's what shellcheck currently says:
$ shellcheck myscript
No issues detected!
$
Here's what I wanted or expected to see:
$ shellcheck myscript
[Line 1:]()
#!/bin/bash -eu
^-- [SC2xxx](https://www.shellcheck.net/wiki/SCxxxx) (warning): Executables must start with `#!/bin/bash` and a minimum number of flags. Use `set` to set shell options so that calling your script as` bash script_name` does not break its functionality.
$
Suggested by Google Shell Style Guide (https://google.github.io/styleguide/shellguide.html#which-shell-to-use).
There is an error in the same neighbourhood (https://github.com/koalaman/shellcheck/wiki/SC2096)