ShellCheck 0.9 is available, a static analyzer for shell scripts

The release of the ShellCheck 0.9 project has been published, which develops a system for static analysis of shell scripts that supports error detection in scripts, taking into account the features of bash, sh, ksh and dash. The project code is written in Haskell and distributed under the GPLv3 license. Components are provided for integration with Vim, Emacs, VSCode, Sublime, Atom, and various frameworks that support GCC-compliant error reporting.

ShellCheck 0.9 is available, a static analyzer for shell scripts

It is supported to detect both syntactical errors in the code, leading to the output of an error by the interpreter at the time of execution, and semantic problems, due to which the execution is not violated, but anomalies in the behavior of the script occur. The analyzer can also identify bottlenecks, non-obvious problems and pitfalls that can lead to failures under certain circumstances.

From the classes of detected errors, one can note problems with escaping special characters and framing in quotation marks, errors in conditional expressions, incorrect use of commands, problems with processing time and dates, and typical syntax errors for beginners. For example, the absence of spaces when comparing "[[ $foo==0 ]]", the presence of spaces "var = 42" or specifying the $ symbol when assigning "$foo=42", the use of variables without quotes "echo $1", specifying extra square brackets in "tr -cd '[a-zA-Z0-9]'",

Additionally, it supports the output of recommendations for improving the style of the code, eliminating portability problems and improving the reliability of scripts. For example, instead of "echo $[1+2]" it will be suggested to use the syntax "$((..))", the construct 'rm -rf "$STEAMROOT/"*' will be marked as unsafe and capable of removing the root directory if the variable is not filled $STEAMROOT and using "echo {1..10}" will be highlighted as incompatible with dash and sh.

In the new version:

  • Added a warning for expressions like 'local readonly foo'.
  • Added warning about unavailable commands.
  • Added backreference warning to 'declare x=1 y=$x'.
  • Added warning if $? used to issue the return code of echo, printf, [ ], [[ ]] and test.
  • Added recommendation to remove ((..))inarray[((idx))]=val.
  • Added recommendation for concatenating double brackets in arithmetic contexts.
  • Added recommendation to remove parentheses in the expression a[(x+1)]=val.

Source: opennet.ru

Add a comment