2018-06-20 12:12:26 +01:00
|
|
|
# shellcheck
|
|
|
|
|
|
|
|
> Shell script static analysis tool.
|
2021-04-16 14:15:12 +01:00
|
|
|
> Check shell scripts for errors, usage of deprecated/insecure features, and bad practices.
|
|
|
|
> More information: <https://www.shellcheck.net>.
|
2018-06-20 12:12:26 +01:00
|
|
|
|
|
|
|
- Check a shell script:
|
|
|
|
|
2021-04-16 14:15:12 +01:00
|
|
|
`shellcheck {{path/to/script.sh}}`
|
2018-06-20 12:12:26 +01:00
|
|
|
|
2021-04-16 14:15:12 +01:00
|
|
|
- Check a shell script interpreting it as the specified shell dialect (overrides the shebang at the top of the script):
|
2018-06-20 12:12:26 +01:00
|
|
|
|
2021-04-16 14:15:12 +01:00
|
|
|
`shellcheck --shell {{sh|bash|dash|ksh}} {{path/to/script.sh}}`
|
2018-06-20 12:12:26 +01:00
|
|
|
|
2021-04-16 14:15:12 +01:00
|
|
|
- Ignore one or more error types:
|
2018-06-20 12:12:26 +01:00
|
|
|
|
2021-04-16 14:15:12 +01:00
|
|
|
`shellcheck --exclude {{SC1009,SC1073}} {{path/to/script.sh}}`
|
2018-06-20 12:12:26 +01:00
|
|
|
|
2021-04-16 14:15:12 +01:00
|
|
|
- Also check any sourced shell scripts:
|
2018-06-20 12:12:26 +01:00
|
|
|
|
2023-09-26 04:19:23 +01:00
|
|
|
`shellcheck --check-sourced {{path/to/script.sh}}`
|
2021-04-16 14:15:12 +01:00
|
|
|
|
|
|
|
- Display output in the specified format (defaults to `tty`):
|
|
|
|
|
|
|
|
`shellcheck --format {{tty|checkstyle|diff|gcc|json|json1|quiet}} {{path/to/script.sh}}`
|
|
|
|
|
|
|
|
- Enable one or more optional checks:
|
|
|
|
|
|
|
|
`shellcheck --enable={{add-default-case|avoid-nullary-conditions}}`
|
|
|
|
|
|
|
|
- List all available optional checks that are disabled by default:
|
|
|
|
|
|
|
|
`shellcheck --list-optional`
|