← 返回命令列表

Linux command

shellcheck 命令

网络

复制后可按需替换文件名、目录或参数。

常用示例

Check a shell script

shellcheck [script.sh]

Check multiple scripts

shellcheck [script1.sh] [script2.sh]

Check with specific shell dialect

shellcheck --shell=[bash|sh|dash|ksh] [script.sh]

Output in different format

shellcheck --format=[json|gcc|checkstyle] [script.sh]

Exclude specific warnings

shellcheck --exclude=[SC2034,SC2086] [script.sh]

Check script from stdin

cat [script.sh] | shellcheck -

Enable optional checks

shellcheck --enable=all [script.sh]

说明

shellcheck is a static analysis tool for shell scripts. It detects bugs, syntax issues, and pitfalls in bash/sh/ksh/dash scripts, providing explanations and suggestions for fixes. Each warning has a code (e.g., SC2086) linking to detailed wiki documentation explaining the issue, why it matters, and how to fix it. This makes shellcheck excellent for learning shell scripting best practices. The tool catches common issues like unquoted variables, deprecated syntax, command substitution pitfalls, and potential security vulnerabilities. It distinguishes between different shell dialects and their specific features. Integration is available for most editors (VS Code, Vim, Emacs, Sublime) and CI systems, enabling automated script checking.

参数

-s, --shell _dialect_
Specify shell dialect (sh, bash, dash, ksh)
-f, --format _format_
Output format (tty, gcc, json, checkstyle, diff, quiet)
-e, --exclude _codes_
Exclude specific error codes (comma-separated)
-i, --include _codes_
Include only specific error codes
--enable _checks_
Enable optional checks (all, require-variable-braces, etc.)
-x, --external-sources
Follow and check sourced files
-a, --check-sourced
Check sourced files for issues
-S, --severity _level_
Minimum severity (error, warning, info, style)
-V, --version
Display version
-C, --color _when_
Colorize output (auto, always, never).
--wiki-link-count _n_
Include wiki links for first n warnings.

FAQ

What is the shellcheck command used for?

shellcheck is a static analysis tool for shell scripts. It detects bugs, syntax issues, and pitfalls in bash/sh/ksh/dash scripts, providing explanations and suggestions for fixes. Each warning has a code (e.g., SC2086) linking to detailed wiki documentation explaining the issue, why it matters, and how to fix it. This makes shellcheck excellent for learning shell scripting best practices. The tool catches common issues like unquoted variables, deprecated syntax, command substitution pitfalls, and potential security vulnerabilities. It distinguishes between different shell dialects and their specific features. Integration is available for most editors (VS Code, Vim, Emacs, Sublime) and CI systems, enabling automated script checking.

How do I run a basic shellcheck example?

Run `shellcheck [script.sh]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.

What does -s, --shell _dialect_ do in shellcheck?

Specify shell dialect (sh, bash, dash, ksh)