# ShellCheck

> Static analysis tool that identifies syntax errors, semantic problems, and pitfalls in bash/sh shell scripts

Stars: 40.3k · Language: Haskell · License: GPL-3.0 · Categories: Dev Tools

- Repository: https://github.com/koalaman/shellcheck
- Website: https://www.shellcheck.net
- Page: https://www.trmn.sh/tools/shellcheck

## Install

- Homebrew: `brew install shellcheck`
- APT: `sudo apt install shellcheck`
- Cabal: `cabal update && cabal install ShellCheck`

## Overview

ShellCheck is a static analysis tool that examines bash and sh shell scripts to identify common issues that cause scripts to fail or behave unexpectedly. It detects beginner syntax errors that produce cryptic shell error messages, intermediate-level semantic problems that cause strange behavior, and subtle pitfalls that may break otherwise working scripts under certain conditions.

The tool analyzes scripts for problems across multiple categories including quoting issues, conditional logic errors, misused commands, data typing problems, and portability concerns. ShellCheck can be used through a web interface at shellcheck.net, as a command-line tool, or integrated directly into editors like Vim, Emacs, VSCode, and Sublime Text through various plugins.

ShellCheck outputs warnings in multiple formats including human-readable text, JSON, CheckStyle-compatible XML, and GCC-compatible format for build system integration. It can be incorporated into CI/CD pipelines and is pre-installed on services like Travis CI, GitHub Actions, and CircleCI. The tool supports both interactive development workflows and automated testing environments, making it suitable for individual developers and teams maintaining shell script codebases.

### Installation

```bash
# via Homebrew
brew install shellcheck
```

```bash
# via APT
sudo apt install shellcheck
```

```bash
# via Cabal
cabal update && cabal install ShellCheck
```

![Terminal screenshot showing ShellCheck analyzing a problematic shell script](https://media.trmn.sh/cached/84f1acf3c2516fe9c9da1a7d900b56cd5af4a39e0a36f327059888a97f30afcc.png)

![Vim editor with inline ShellCheck feedback](https://media.trmn.sh/cached/035ced7c9dafeadc3cbe212fe9a7d0232a0ffa2c880472f803cbf0ad39250f52.png)

![Emacs editor with inline ShellCheck feedback](https://media.trmn.sh/cached/42b2a3a66cefcae52bd1e58224da898cbfeee01effd909168e66c76bfaf4c344.png)

## Alternatives

- [hadolint](https://www.trmn.sh/tools/hadolint.md): Dockerfile linter that parses AST and integrates with ShellCheck to validate Docker best practices and bash code in RUN instructions (Haskell, 12.5k stars)
- [trivy](https://www.trmn.sh/tools/trivy.md): Security scanner that detects vulnerabilities, secrets, and misconfigurations in containers, filesystems, git repos, VMs, and Kubernetes (Go, 38.9k stars)
- [just](https://www.trmn.sh/tools/just.md): Command runner that saves and runs project-specific commands from a justfile with make-inspired syntax (Rust, 36.5k stars)
- [zellij](https://www.trmn.sh/tools/zellij.md): Terminal multiplexer with floating panes, multiplayer collaboration, WebAssembly plugins, and built-in web client (Rust, 35.9k stars)
- [mise](https://www.trmn.sh/tools/mise.md): CLI tool for managing development environments with version-controlled tools, environment variables, and tasks (Rust, 35.7k stars)

## Guides

- [Lint and test a shell script with ShellCheck and Bats](https://www.trmn.sh/guides/shellcheck-bats-workflow): Catch a quoting bug with ShellCheck, then add Bats tests for names containing spaces and wildcard characters.
- [Best Tools for Testing and Linting Shell Scripts](https://www.trmn.sh/best/shell-script-quality-tools): Compare ShellCheck, Bats-core, pre-commit: workflows, strengths and tradeoffs.

---

Canonical: https://www.trmn.sh/tools/shellcheck
