ShellCheck
is a static analysis tool for shell scripts. It warns you about syntax errors, bad practices, and potential bugs.
This guide shows how to:
shellcheck
locallyShellCheck analyzes Bash scripts and reports:
sudo apt install shellcheck
brew install shellcheck
Download from: https://github.com/koalaman/shellcheck/releases
Run it on a script:
shellcheck script.sh
To check all scripts in your repo:
find . -name "*.sh" -exec shellcheck {} \;
shellcheck.yml
Create .github/workflows/shellcheck.yml
:
name: ShellCheck Linter
on:
push:
paths:
- '**.sh'
pull_request:
paths:
- '**.sh'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install ShellCheck
run: sudo apt-get install -y shellcheck
- name: Run ShellCheck
run: |
find . -name "*.sh" | xargs shellcheck
.sh
files on push/PRIn script.sh line 4:
for f in $(ls *.txt); do
^-- SC2045: Iterating over ls output is fragile. Use globs.
Practice | Why |
---|---|
Fix all shellcheck warnings |
Improve reliability |
Run on every PR | Maintain quality |
Use consistent quoting | Prevent bugs |
Enable set -euo pipefail in scripts |
Add extra safety |
๐ File:
advance/shellcheck-ci.md
Author: Kashif Alam