2018-06-20 07:12:26 -04:00
|
|
|
# shellcheck
|
|
|
|
|
2024-03-13 03:52:57 +11:00
|
|
|
> 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 07:12:26 -04:00
|
|
|
|
|
|
|
- Check a shell script:
|
|
|
|
|
2021-04-16 09:15:12 -04:00
|
|
|
`shellcheck {{path/to/script.sh}}`
|
2018-06-20 07:12:26 -04:00
|
|
|
|
2025-04-12 15:42:06 +03:00
|
|
|
- Check a shell script interpreting it as the specified shell dialect (overrides the shebang at the top of the script):
|
2018-06-20 07:12:26 -04:00
|
|
|
|
2025-04-12 15:42:06 +03:00
|
|
|
`shellcheck {{[-s|--shell]}} {{sh|bash|dash|ksh}} {{path/to/script.sh}}`
|
2018-06-20 07:12:26 -04:00
|
|
|
|
2025-04-12 15:42:06 +03:00
|
|
|
- Ignore one or more error types:
|
2018-06-20 07:12:26 -04:00
|
|
|
|
2025-04-12 15:42:06 +03:00
|
|
|
`shellcheck {{[-e|--exclude]}} {{SC1009,SC1073,...}} {{path/to/script.sh}}`
|
2018-06-20 07:12:26 -04:00
|
|
|
|
2021-04-16 09:15:12 -04:00
|
|
|
- Also check any sourced shell scripts:
|
2018-06-20 07:12:26 -04:00
|
|
|
|
2025-04-12 15:42:06 +03:00
|
|
|
`shellcheck {{[-a|--check-sourced]}} {{path/to/script.sh}}`
|
2021-04-16 09:15:12 -04:00
|
|
|
|
2025-04-12 15:42:06 +03:00
|
|
|
- Display output in the specified format (defaults to `tty`):
|
2021-04-16 09:15:12 -04:00
|
|
|
|
2025-04-12 15:42:06 +03:00
|
|
|
`shellcheck {{[-f|--format]}} {{tty|checkstyle|diff|gcc|json|json1|quiet}} {{path/to/script.sh}}`
|
2021-04-16 09:15:12 -04:00
|
|
|
|
2024-03-13 03:52:57 +11:00
|
|
|
- Enable one or more [o]ptional checks:
|
2021-04-16 09:15:12 -04:00
|
|
|
|
2025-04-12 15:42:06 +03:00
|
|
|
`shellcheck {{[-o|--enable]}} {{add-default-case,avoid-nullary-conditions,...}} {{path/to/script.sh}}`
|
2021-04-16 09:15:12 -04:00
|
|
|
|
|
|
|
- List all available optional checks that are disabled by default:
|
|
|
|
|
|
|
|
`shellcheck --list-optional`
|
2024-03-13 03:52:57 +11:00
|
|
|
|
2025-04-12 15:42:06 +03:00
|
|
|
- Adjust the level of severity to consider (defaults to `style`):
|
2024-03-13 03:52:57 +11:00
|
|
|
|
2025-04-12 15:42:06 +03:00
|
|
|
`shellcheck {{[-S|--severity]}} {{error|warning|info|style}} {{path/to/script.sh}}`
|