Files
tldr/pages.zh/common/shellcheck.md

36 lines
1.1 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# shellcheck
> 静态检查 shell 脚本中的错误、过时/不安全特性以及不良实践。
> 更多信息:<https://github.com/koalaman/shellcheck/wiki>。
- 检查一个 shell 脚本:
`shellcheck {{path/to/script.sh}}`
- 按照指定的 [s]hell 方言检查一个 shell 脚本(覆盖脚本顶部的 shebang
`shellcheck --shell {{sh|bash|dash|ksh}} {{path/to/script.sh}}`
- 忽略一个或多个错误类型:
`shellcheck --exclude {{SC1009,SC1073,...}} {{path/to/script.sh}}`
- 还检查任何源自的 shell 脚本:
`shellcheck --check-sourced {{path/to/script.sh}}`
- 以指定的 [f]ormat 显示输出(默认为 `tty`
`shellcheck --format {{tty|checkstyle|diff|gcc|json|json1|quiet}} {{path/to/script.sh}}`
- 启用一个或多个 [o]ptional 检查:
`shellcheck --enable {{add-default-case,avoid-nullary-conditions,...}} {{path/to/script.sh}}`
- 列出所有默认被禁用的可选检查:
`shellcheck --list-optional`
- 调整考虑的 [S]everity 级别(默认为 `style`
`shellcheck --severity {{error|warning|info|style}} {{path/to/script.sh}}`