Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
shellcheck

shellcheck

> 开发工具
Free

ShellCheck, a static analysis tool for shell scripts

40.1K stars0 likes0 views
WebsiteGitHub

About

ShellCheck, a static analysis tool for shell scripts

ShellCheck - A shell script static analysis tool

ShellCheck is a GPLv3 tool that gives warnings and suggestions for bash/sh shell scripts:

The goals of ShellCheck are

  • To point out and clarify typical beginner's syntax issues that cause a shell to give cryptic error messages.

  • To point out and clarify typical intermediate level semantic problems that cause a shell to behave strangely and counter-intuitively.

  • To point out subtle caveats, corner cases and pitfalls that may cause an advanced user's otherwise working script to fail under future circumstances.

See the gallery of bad code for examples of what ShellCheck can help you identify!

Table of Contents

  • How to use
    • On the web
    • From your terminal
    • In your editor
    • In your build or test suites
  • Installing
  • Compiling from source
    • Installing Cabal
    • Compiling ShellCheck
    • Running tests
  • Gallery of bad code
    • Quoting
    • Conditionals
    • Frequently misused commands
    • Common beginner's mistakes
    • Style
    • Data and typing errors
    • Robustness
    • Portability
    • Miscellaneous
  • Testimonials
  • Ignoring issues
  • Reporting bugs
  • Contributing
  • Copyright
  • Other Resources

How to use

There are a number of ways to use ShellCheck!

On the web

Paste a shell script on for instant feedback.

ShellCheck.net is always synchronized to the latest git commit, and is the easiest way to give ShellCheck a go. Tell your friends!

From your terminal

Run shellcheck yourscript in your terminal for instant output, as seen above.

In your editor

You can see ShellCheck suggestions directly in a variety of editors.

  • Vim, through ALE, Neomake, or Syntastic:

.

  • Emacs, through Flycheck or Flymake:

.

  • Sublime, through SublimeLinter.

  • Pulsar Edit (former Atom), through linter-shellcheck-pulsar.

  • VSCode, through vscode-shellcheck.

  • Most other editors, through GCC error compatibility.

In your build or test suites

While ShellCheck is mostly intended for interactive use, it can easily be added to builds or test suites. It makes canonical use of exit codes, so you can just add a shellcheck command as part of the process.

For example, in a Makefile:

makefile
check-scripts:
    # Fail if any of these files have warnings
    shellcheck myscripts/*.sh

or in a Travis CI .travis.yml file:

yaml
script:
  # Fail if any of these files have warnings
  - shellcheck myscripts/*.sh

Services and platforms that have ShellCheck pre-installed and ready to use:

  • Travis CI
  • Codacy
  • Code Climate
  • Code Factor
  • Codety via the Codety Scanner
  • CircleCI via the ShellCheck Orb
  • Github (only Linux)
  • Trunk Code Quality (universal linter; allows you to explicitly version your shellcheck install) via the shellcheck plugin
  • CodeRabbit

Most other services, including GitLab, let you install ShellCheck yourself, either through the system's package manager (see Installing), or by downloading and unpacking a binary release.

It's a good idea to manually install a specific ShellCheck version regardless. This avoids any surprise build breaks when a new version with new warnings is published.

For customized filtering or reporting, ShellCheck can output simple JSON, CheckStyle compatible XML, GCC compatible warnings as well as human readable text (with or without ANSI colors). See the Integration wiki page for more documentation.

Installing

The easiest way to install ShellCheck locally is through your package manager.

On systems with Cabal (installs to ~/.cabal/bin):

cabal update
cabal install ShellCheck

On systems with Stack (installs to ~/.local/bin):

stack update
stack install ShellCheck

On Debian based distros:

bash
sudo apt install shellcheck

On Arch Linux based distros:

pacman -S shellcheck

or get the dependency free shellcheck-bin from the AUR.

On Gentoo based distros:

emerge --ask shellcheck

On EPEL based distros:

bash
sudo yum -y install epel-release
sudo yum install ShellCheck

On Fedora based distros:

dnf install ShellCheck

On FreeBSD:

pkg install hs-ShellCheck

On macOS (OS X) with Homebrew:

bash
brew install shellcheck

Or with MacPorts:

bash
sudo port install shellcheck

On OpenBSD:

pkg_add shellcheck

On openSUSE

zypper in ShellCheck

Or use OneClickInstall -

On Solus:

eopkg install shellcheck

On Windows (via chocolatey):

cmd
C:\> choco install shellcheck

Or Windows (via winget):

cmd
C:\> winget install --id koalaman.shellcheck

Or Windows (via scoop):

cmd
C:\> scoop install shellcheck

From conda-forge:

conda install -c conda-forge shellcheck

From Snap Store:

snap install --channel=edge shellcheck

From Docker Hub:

bash
docker run --rm -v "$PWD:/mnt" koalaman/shellcheck:stable myscript
# Or :v0.4.7 for that version, or :latest for daily builds

or use koalaman/shellcheck-alpine if you want a larger Alpine Linux based image to extend. It works exactly like a regular Alpine image, but has shellcheck preinstalled.

Using the nix package manager:

bash
nix-env -iA nixpkgs.shellcheck

Using the Flox package manager

bash
flox install shellcheck

Alternatively, you can download pre-compiled binaries for the latest release here:

  • Linux, x86_64 (statically linked)
  • Linux, armv6hf, i.e. Raspberry Pi (statically linked)
  • Linux, aarch64 aka ARM64 (statically linked)
  • macOS, aarch64
  • macOS, x86_64
  • Windows, x86

or see the GitHub Releases for other releases (including the latest meta-release for daily git builds).

There are currently no official binaries for Apple Silicon, but third party builds are available via ShellCheck for Visual Studio Code.

Distro packages already come with a man page. If you are building from source, it can be installed with:

bash
pandoc -s -f markdown-smart -t man shellcheck.1.md -o shellcheck.1
sudo mv shellcheck.1 /usr/share/man/man1

pre-commit

To run ShellCheck via pre-commit, add the hook to your .pre-commit-config.yaml:

repos:
-   repo: https://github.com/koalaman/shellcheck-precommit
    rev: v0.11.0
    hooks:
    -   id: shellcheck
#       args: ["--severity=warning"]  # Optionally only show errors and warnings

Travis CI

Travis CI has now integrated ShellCheck by default, so you don't need to manually install it.

If you still want to do so in order to upgrade at your leisure or ensure you're using the latest release, follow the steps below to install a binary version.

Installing a pre-compiled binary

The pre-compiled binaries come in tar.xz files. To decompress them, make sure xz is installed. On Debian/Ubuntu/Mint, you can apt install xz-utils. On Redhat/Fedora/CentOS, yum -y install xz.

A simple installer may do something like:

bash
scversion="stable" # or "v0.4.7", or "latest"
wget -qO- "https://github.com/koalaman/shellcheck/releases/download/${scversion?}/shellcheck-${scversion?}.linux.x86_64.tar.xz" | tar -xJv
cp "shellcheck-${scversion}/shellcheck" /usr/bin/
shellcheck --version

Compiling from source

This section describes how to build ShellCheck from a source directory. ShellCheck is written in Haskell and requires 2GB of RAM to compile.

Installing Cabal

ShellCheck is built and packaged using Cabal. Install the package cabal-install from your system's package manager (with e.g. apt-get, brew, emerge, yum, or zypper).

On macOS (OS X), you can do a fast install of Cabal using brew, which takes a couple of minutes instead of more than 30 minutes if you try to compile it from source.

$ brew install cabal-install

On MacPorts, the package is instead called hs-cabal-install, while native Windows users should install the latest version of the Haskell platform from

Verify that cabal is installed and update its dependency list with

$ cabal update

Compiling ShellCheck

git clone this repository, and cd to the ShellCheck source directory to build/install:

$ cabal install

This will compile ShellCheck and install it to your ~/.cabal/bin directory.

Add this directory to your PATH (for bash, add this to your ~/.bashrc):

bash
export PATH="$HOME/.cabal/bin:$PATH"

Log out and in again, and verify that your PATH is set up correctly:

bash
$ which shellcheck
~/.cabal/bin/shellcheck

On native Windows, the PATH should already be set up, but the system may use a legacy codepage. In cmd.exe, powershell.exe and Powershell ISE, make sure to use a TrueType font, not a Raster font, and set the active codepage to UTF-8 (65001) with chcp:

cmd
chcp 65001

In Powershell ISE, you may need to additionally update the output encoding:

powershell
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8

Running tests

To run the unit test suite:

$ cabal test

Gallery of bad code

So what kind of things does ShellCheck look for? Here is an incomplete list of detected issues.

Quoting

ShellCheck can recognize several types of incorrect quoting:

…

Conditionals

ShellCheck can recognize many types of incorrect test statements.

…

Frequently misused commands

ShellCheck can recognize instance

Issues· 1120 open

View all issuesOpen on GitHub
  • #3524

    SC2118 is false

    Updated Sep 29, 2026
  • #1113

    Useless grep | awk

    Updated Sep 29, 2026
  • #2321

    SC3037: echo flags

    Updated Sep 28, 2026
  • #3007

    SC2206: Exception for integer variables

    Updated Sep 28, 2026
  • #3262

    local is undefined in ksh93, but not flagged.

    Updated Sep 26, 2026
  • #3543

    Shellcheck does not issue unused variable error when local variable shadows global

    Updated Sep 26, 2026
  • #2171

    local associative array seen as global

    Updated Sep 26, 2026
  • #3542

    Feature request: warning when globstar seems to be used but not set

    Updated Sep 25, 2026
  • #2426

    Weird behaviour when bash function has the Unicode name

    Updated Sep 24, 2026
  • #2574

    Catch undefined commands / functions

    Updated Sep 22, 2026

> Tags

Haskellbashdeveloper-toolshaskell

No comments yet. Be the first to share.

> Details

PublishedSep 26, 2026
UpdatedOct 1, 2026
Category开发工具
PricingFree

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具