Bash scripts - Using ShellCheck to check .sh files
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.
- https://github.com/koalaman/shellcheck
- demo: https://www.shellcheck.net/
- examples (untested yet) with Gitlab CI: https://github.com/koalaman/shellcheck/wiki/GitLab-CI
# ShellCheck https://github.com/koalaman/shellcheck/wiki/GitLab-CI
# --> simple test job for GitLab (analyse testScript.sh):
test:
image: koalaman/shellcheck-alpine:latest
stage: test
script:
- shellcheck testScript.sh
# ShellCheck https://github.com/koalaman/shellcheck/wiki/GitLab-CI
# https://git-scm.com/docs/git-ls-files
# --> a CI job that will lint all shell scripts in a git repository:
test:
image: koalaman/shellcheck-alpine:latest
stage: test
before_script:
- apk update
- apk add git
script:
- git ls-files --exclude='*.sh' --ignored | xargs shellcheck
Edited by Fabrice Gangler