Support multiple shells
I've got a script that attempts to be compatible with sh, dash, bash, zsh, and ksh. I'd love to specify multiple shells, so I don't have to manually merge and dedupe all the errors across the shells.
Do you have guarded shell specific code in this script, e.g. if [ -n "$BASH_VERSION" ]; then bash-specific-code-here; fi?
If not, just setting the shell to sh should be enough. It's the lowest common denominator. Anything that passes cleanly for sh is unlikely to have any useful output for any of the other shells.
Yes, I do. However, I've also gotten dash warnings that I don't get in sh, for things like local and type.
What I did was just put my Bash-specific stuff into a separate file. So like:
# shellcheck shell=sh
... # POSIX-compatible stuff for all shells
if [ -n "$BASH_VERSION" ]; then . features.bash; fi
I guess doing so helps me keep things neat. :)
Originally I was hoping to do something like:
# shellcheck shell=sh
... # POSIX-compatible stuff for all shells
# shellcheck shell=bash
if [ -n "$BASH_VERSION" ]; then . features.bash; fi
Where everything below our shellcheck directives can be checked against their corresponding shell, but it looks like shellcheck only looks for a directive in the first block of comments from the top of the file.
Unfortunately that’s not an option for my project; as it needs to be distributed, from git, as a single file.
Any possibility that a shellcheck "shell" directive could be a comma-separated list?
This is a nice feature request. For example, my ~/.profile is supposed to be compatible with sh, bash, and zsh, since I source it in both Bash and ZSH initialization.