koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts

Home Page:https://www.shellcheck.net

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

New Rule: Executables must start with `#!/bin/bash` and a minimum number of flags.

stdedos opened this issue · comments

For bugs

For new checks and feature suggestions

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)