Using shellcheck With BBEdit
Once you have the shellcheck command installed, you can also invoke from within BBEdit: When you have a script open in BBEdit, verify that the script is recognized as a ‘Unix shell script.’ Then you can select ‘Check Syntax…’ from the ‘#!’ menu (keyboard shortcut ⌘-K). This will open a second window with all the issues shellcheck has found.
Unfortunately, given that Apple is phasing out bash
, it doesn’t work with zsh
.
Previously:
Update (2022-04-13): Matt Sephton:
zsh -n $FILENAME
and/orzsh -x $FILENAME
(non_exec and debug mode respectively) are a reasonable workaround. Not shellcheck good but workable.
So true. And it doesn't seem like they plan to support zsh anytime soon (https://github.com/koalaman/shellcheck/issues/809).
I've been using the following workaround using zsh's Bash emulation mode:
#!/bin/zsh
# shellcheck shell=bash
emulate -LR bash