The release of ShellCheck 0.9 has been published, enhancing the static analysis system for shell scripts that supports error detection considering the specifics of bash, sh, ksh, and dash. The project's code is written in Haskell and is distributed under the GPLv3 license. Components are provided for integration with Vim, Emacs, VSCode, Sublime, Atom, and various integrated environments that support GCC-compatible error output.

It supports the detection of both syntax errors in the code leading to interpreter errors at runtime and semantic issues that do not interrupt execution but cause anomalies in script behavior. The analyzer can also identify bottlenecks, non-obvious problems, and pitfalls that may lead to failures under certain circumstances.
Notable categories of detected errors include issues with escaping special characters and quoting, errors in conditional expressions, incorrect use of commands, problems with date and time handling, and typical syntax errors made by beginners. For example, missing spaces in comparisons ‘[[ $foo==0 ]]’, having spaces in ‘var = 42’, or using the $ symbol in assignment ‘$foo=42’, using variables without quotes ‘echo $1’, and including unnecessary square brackets in ‘tr -cd ‘[a-zA-Z0-9]’.
Additionally, it provides recommendations for improving code style, addressing portability issues, and enhancing script reliability. For instance, instead of ‘echo $[1+2]’, it is suggested to use the syntax ‘$((..))’, the construction ‘rm -rf ‘$STEAMROOT/‘*’ will be flagged as unsafe and capable of deleting the root directory if the $STEAMROOT variable is unset, and using ‘echo {1..10}’ will be highlighted as incompatible with dash and sh.
In the new version:
- A warning has been added for expressions like ‘local readonly foo’.
- A warning has been added regarding unavailable commands.
- A warning has been added about back-references in ‘declare x=1 y=$x’.
- A warning has been added if $? is used to return the exit code of echo, printf, [ ], [[ ]] and test.
- A recommendation has been added to remove ((..))inarray[((idx))]=val.
- A recommendation has been added to combine double parentheses in arithmetic contexts.
- A recommendation was added for removing round brackets in the expression a[(x+1)]=val.
Source: opennet.ru
