tldr/pages/common/shellcheck.md

37 lines
1.1 KiB
Markdown
Raw Normal View History

2018-06-20 12:12:26 +01:00
# shellcheck
> Statically check shell scripts for errors, usage of deprecated/insecure features, and bad practices.
> More information: <https://github.com/koalaman/shellcheck/wiki>.
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
- Check a shell script interpreting it as the specified [s]hell 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
- Ignor[e] one or more error types:
2018-06-20 12:12:26 +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 [f]ormat (defaults to `tty`):
2021-04-16 14:15:12 +01:00
`shellcheck --format {{tty|checkstyle|diff|gcc|json|json1|quiet}} {{path/to/script.sh}}`
- Enable one or more [o]ptional checks:
2021-04-16 14:15:12 +01:00
`shellcheck --enable {{add-default-case,avoid-nullary-conditions,...}} {{path/to/script.sh}}`
2021-04-16 14:15:12 +01:00
- List all available optional checks that are disabled by default:
`shellcheck --list-optional`
- Adjust the level of [S]everity to consider (defaults to `style`):
`shellcheck --severity {{error|warning|info|style}} {{path/to/script.sh}}`