$ echo -e "# shellcheck disable=SC2148\n:" >test
$ shellcheck test
In test line 1:
# shellcheck disable=SC2148
^-- SC2148: Include a shebang (#!) to specify the shell.
It's even colored red as an error, not a warning. No, I don't want a shebang - some scripts are only meant to be sourced, and should not be executed on their own. In fact, it would be nice if disable=SC2148 could be placed anywhere in the file, so the first line can be reserved for comments.
If you don't want it to be executed on its own, wouldn't it make even more sense to specify e.g. #!/bin/sh -n? That way non-execution is enforced.
Consider .profile, which can be sourced by several different shells.
Or all the /etc/profile.d/*.sh scripts in distros like Fedora, which also are shell-agnostic.
Also, consider the following script named "shell", the purpose of which is to set the SHELL variable correctly if sourced, or report which shell you're using if called from the command line:
SHELL=$(readlink /proc/$$/exe)
export SHELL
[ -t 0] && echo "$SHELL"
They're not shell agnostic. They're targeting POSIX sh, the lowest common denominator Bourne shell.
This is fixed or at least alleviated in 0369f43b. If you have files where you don't want a shebang, you can specify the dialect with shellcheck -s dialect.
Most helpful comment
Consider .profile, which can be sourced by several different shells.
Or all the /etc/profile.d/*.sh scripts in distros like Fedora, which also are shell-agnostic.
Also, consider the following script named "shell", the purpose of which is to set the SHELL variable correctly if sourced, or report which shell you're using if called from the command line: