How to Lint Shell Scripts With ShellCheck in GitHub Actions
ShellCheck flags quoting, portability, and logic bugs in shell scripts, and it ships preinstalled on Ubuntu runners.
Run shellcheck over your scripts in a CI step. It is already on GitHub-hosted Ubuntu runners, so you can gate merges on clean shell scripts with no install step.
Steps
- Point
shellcheckat your script files or a scripts directory. - Fail the job on any finding so problems block the merge.
- Add inline
# shellcheck disable=SCxxxxcomments for justified exceptions.
Workflow
.github/workflows/ci.yml
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: shellcheck scripts/*.shGotchas
- ShellCheck needs a shebang or
-s bashto know the dialect; add one or pass the shell explicitly. - Use
find . -name "*.sh" -print0 | xargs -0 shellcheckto cover nested directories.
Related guides
How to Run a pre-commit Check Script in GitHub ActionsEnforce the same pre-commit hooks in GitHub Actions that developers run locally by installing pre-commit and…
How to Use set -euo pipefail in GitHub Actions ScriptsMake GitHub Actions bash scripts fail loudly by starting them with set -euo pipefail, so unset variables and…