ShellCheck
From Gentoo Wiki
ShellCheck is a shell script static analysis tool written in Haskell. It gives various warnings about shell scripts — mainly syntax and semantic problems related to the typical beginner issues, counter-intuitive behavior, or various corner cases.
As of version 0.9.0, ShellCheck supports sh, bash, dash, and ksh shells.[1]
It can be integrated in a build suite or CI/CD pipelines such as Jenkins or GitLab.
Installation
USE flags
USE flags for dev-util/shellcheck Shell script analysis tool
doc
|
Add extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally |
hscolour
|
Include coloured haskell sources to generated documentation (dev-haskell/hscolour) |
profile
|
Add support for software performance analysis (will likely vary from ebuild to ebuild) |
test
|
Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently) |
Emerge
Tip
The binary version is intended for systems with no Haskell toolchain present.
The binary version is intended for systems with no Haskell toolchain present.
Binary package (shellcheck-bin)
root #
emerge --ask dev-util/shellcheck-bin
Source package
root #
emerge --ask dev-util/shellcheck
Configuration
Files
ShellCheck's behavior can be modified using directives (like disable or enable) directly in the validated script or using configuration files:
- ~/.shellcheckrc - Local (per user) configuration file.
- /home/larry/project/.shellcheckrc - Per project configuration file.
Usage
Invocation
Script validation with an example error output:
user $
shellcheck validated-script.sh
In validated-script.sh line 5: echo $DATE ^---^ SC2086 (info): Double quote to prevent globbing and word splitting. Did you mean: echo "$DATE" For more information: https://www.shellcheck.net/wiki/SC2086 -- Double quote to prevent globbing ...
See also
- Shell — command-line interpreter that offers a text-based interface to users.
References
- ↑ ShellCheck: SC1008, GitHub. Retrieved on January 30, 2023