shellcheck v0.6.0 release: static analysis tool for shell scripts

ShellCheck – A shell script static analysis tool

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.

Changelog

v0.6.0 – 2018-12-02

Added

  • Command line option –severity/-S for filtering by minimum severity
  • Command line option –wiki-link-count/-W for showing wiki links
  • SC2152/SC2151: Warn about bad exit values like 1234 and "foo"
  • SC2236/SC2237: Suggest -n/-z instead of ! -z/-n
  • SC2238: Warn when redirecting to a known command name, e.g. ls > rm
  • SC2239: Warn if the shebang is not an absolute path, e.g. #!bin/sh
  • SC2240: Warn when passing additional arguments to dot (.) in sh/dash
  • SC1133: Better diagnostics when starting a line with |/||/&&

Changed

  • Most warnings now have useful end positions
  • SC1117 about unknown double-quoted escape sequences has been retired

Fixed

  • SC2021 no longer triggers for equivalence classes like [=e=]
  • SC2221/SC2222 no longer mistriggers on fall-through case branches
  • SC2081 about glob matches in [ .. ] now also triggers for !=
  • SC2086 no longer warns about spaces in $#
  • SC2164 no longer suggests subshells for cd ..; cmd; cd ..
  • read -a is now correctly considered an array assignment
  • SC2039 no longer warns about LINENO now that it’s POSIX

Installing

On Debian based distros:

apt-get install shellcheck

On Arch Linux based distros:

pacman -S shellcheck

Use

On the web

Paste a shell script on https://www.shellcheck.net for instant feedback.

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.

Screenshot of Vim showing inlined shellcheck feedback.

Screenshot of emacs showing inlined shellcheck feedback.

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 and can output simple JSON, CheckStyle compatible XML, GCC compatible warnings as well as human-readable text (with or without ANSI colors).

Tutorial

Copyright 2012-2018, Vidar ‘koala_man’ Holen and contributors.

Source: https://github.com/koalaman/

Share