Friday, September 25, 2015

ShellCheck v0.3.7 Shell Script Static Analysis Tool

ShellCheck v0.3.7 Shell Script Static Analysis Tool

ShellCheck is a static analysis and linting tool for sh/bash scripts. It’s mainly focused on handling typical beginner and intermediate level syntax errors and pitfalls where the shell just gives a cryptic error message or strange behavior, but it also reports on a few more advanced issues where corner cases can cause delayed failures. Licensed under GPLv3.
logo_shellcheck
The goals of ShellCheck are:
  • To point out and clarify typical beginner’s syntax issues, that causes a shell to give cryptic error messages.
  • To point out and clarify typical intermediate level semantic problems, that causes 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.
  • ShellCheck is written in Haskell, and requires 2 GB of memory to compile.

More Information:

What does ShellCheck check?
Here is an incomplete list of things ShellCheck warns about and suggests improvements to:
Unquoted globs for find/grep
Constant test expressions
Assigning arrays to strings
Redirecting into source file
Existence checks of globs
Globs in regex context
PS1 colors not in \[..\]
Prematurely terminated find -exec
Literal quotes in arguments
Assignment in subshells
Confusing time(1) for builtin
~ in quotes
Single, quoted 'for' argument
Arithmetic truncation
Functions used externally
Unused variables
Looping over ls output
Arguments in aliases
Referencing arrays as strings
Unquoted command expansion
$ in for loop variables
Unquoted $@
Unicode quotes
Attempted redirection of stdout+stderr
Attempted indirect assignment
Attempted indirect reference
Variables in single quotes
Comparing numbers with < or >
Unsupported [ ] operators
Using ~ in $PATH
Quoted =~ regex
Opportunities for grep -q
Tautology due to spacing
Variable brace expansion (Bash)
Commands eating loop input
Decimals arithmetics
Comma separated arrays
Misused 'exec'
Globs that could become options
Common shebang errors
Variables in printf format
Numerical comparison of strings
Prefix assignments in args
Implicit precedence in find
Useless use of echo
Repetitive redirections
Redirecting sudo
[] around ranges in tr
Misquoted traps
&& in [ .. ]
Masked return values
Singlequote closed by apostrophe
Attempting to escape ' in ''
Misused char class globs
Concatenating strings and arrays.
Positional parameter misreference
cd-and-back antipattern
Missing semicolons in loops
Catastrophic rm
$ in assignments
Aliases expanding early
Spaces in assignment
Features shebang may not support
Excessive $()/``