技能 shellcheck-configuration
📦

shellcheck-configuration

安全

为 Shell 脚本质量配置 ShellCheck

也可从以下获取: wshobson

Shell 脚本通常包含难以手动发现的细微 bug 和可移植性问题。本技能提供关于配置和使用 ShellCheck 自动检测和修复 shell 脚本问题的全面指导。

支持: Claude Codex Code(CC)
📊 71 充足
1

下载技能 ZIP

2

在 Claude 中上传

前往 设置 → 功能 → 技能 → 上传技能

3

开启并开始使用

测试它

正在使用“shellcheck-configuration”。 如何修复 SC2086:for i in $list; do echo $i; done

预期结果:

SC2086 警告未引用的变量会导致单词拆分。修复方法:使用 "$list" 或 "${list[@]}" 处理数组。修正后:for i in "$list"; do echo "$i"; done

正在使用“shellcheck-configuration”。 创建用于严格 Bash 验证的 .shellcheckrc

预期结果:

配置设置为 shell=bash,启用可选检查(如 require-variable-braces),并禁用 SC1091(未找到源文件)作为项目默认值。

正在使用“shellcheck-configuration”。 最常见的 ShellCheck 错误有哪些需要修复?

预期结果:

前 5 个:SC2086(未引用变量)、SC1091(源文件)、SC2154(未设置变量)、SC2148(提示)、SC2164(使用 cd 时带 || exit)。每个都有本技能中详细介绍的具体修复方法。

安全审计

安全
v1 • 2/25/2026

All 111 static findings are false positives. The skill contains shell command examples used to demonstrate ShellCheck error codes (SC2086, SC1091, etc.). The scanner misidentified 'SC' as 'C2' keywords. URLs point to legitimate ShellCheck project resources. References to ~/.shellcheckrc and ~/.bashrc are standard config file paths, not malicious file access. The skill is purely educational documentation for ShellCheck static analysis tool.

1
已扫描文件
469
分析行数
5
发现项
1
审计总数

高风险问题 (1)

False Positive: Scanner misidentified ShellCheck error codes as C2 keywords
The static scanner flagged 'C2 keywords' at multiple lines (80, 110, 113, 116, etc.), but these are actually ShellCheck error codes like SC2086, SC1091, SC2119. The scanner misread 'SC' as 'C2'. This is a documentation skill teaching users about ShellCheck error codes - no actual C2/malware content exists.
中风险问题 (3)
False Positive: Shell command examples are documentation content, not execution
The static scanner flagged 'external_commands' (73 occurrences) showing backticks, $(), and shell invocations. These are example shell script patterns shown in the skill to demonstrate what ShellCheck will detect. The skill is teaching users about ShellCheck - not executing these commands.
False Positive: Network URLs are legitimate ShellCheck project resources
Hardcoded URLs point to github.com/koalaman/shellcheck and shellcheck.net - the official ShellCheck project and documentation. These are appropriate resources for a ShellCheck configuration skill.
False Positive: Filesystem references are standard shell config paths
References to ~/.shellcheckrc and ~/.bashrc are standard configuration file paths in shell scripting. These are not malicious file access attempts - they are example configuration file locations.
低风险问题 (1)
False Positive: sudo apt-get install is legitimate installation instruction
Line 263 shows 'sudo apt-get install shellcheck' which is the standard way to install ShellCheck on Debian/Ubuntu systems. This is not privilege escalation for malicious purposes.
审计者: claude

质量评分

38
架构
100
可维护性
87
内容
50
社区
78
安全
100
规范符合性

你能构建什么

DevOps 工程师:CI/CD 管道设置

在 GitHub Actions、GitLab CI 或其他 CI/CD 系统中设置自动化 shell 脚本检查,以便在部署前发现问题。

软件开发者:脚本质量改进

使用 ShellCheck 指导修复现有 shell 脚本错误,提高在 不同 Unix/Linux 环境中的可移植性。

系统管理员:团队代码标准

通过项目级配置和 pre-commit 验证,在团队脚本中强制执行一致的代码质量标准。

试试这些提示

安装 ShellCheck
如何在 macOS、Ubuntu 或从源码安装 ShellCheck?
理解错误代码
ShellCheck 错误 SC2086 是什么意思,如何在我的脚本中修复它?
配置项目设置
为 Bash 项目创建一个 .shellcheckrc 配置文件,启用严格检查但禁用 SC1091 和 SC2119。
CI/CD 集成
向我展示如何将 ShellCheck 集成到 GitHub Actions 工作流中,检查所有 .sh 文件并在发现任何问题时使构建失败。

最佳实践

  • 在 CI/CD 管道中运行 ShellCheck,以便在合并前发现问题
  • 正确配置目标 shell——不要将 Bash 脚本作为 POSIX sh 分析
  • 使用内联指令说明为什么抑制特定警告

避免

  • 在不理解为什么出现警告的情况下禁用警告
  • 为错误的 shell 方言分析脚本(将 Bash 当作 sh)
  • 忽略 ShellCheck 输出而不解决底层问题

常见问题

什么是 ShellCheck?
ShellCheck 是一个静态分析工具,用于发现 shell 脚本中的 bug、警告和问题。它支持 Bash、sh、dash、ksh 和其他 POSIX shell。
如何安装 ShellCheck?
在 macOS 上:brew install shellcheck。在 Ubuntu/Debian 上:apt-get install shellcheck。也可以在 github.com/koalaman/shellcheck 从源码构建。
ShellCheck 错误代码是什么意思?
代码分组:SC1000-1099(解析器错误)、SC2000-2099(shell 问题)、SC2100-2199(引用)、SC3000-3999(POSIX 合规性)。每个代码都有具体指导。
如何抑制特定警告?
使用内联指令:# shellcheck disable=SC2086。或者在 .shellcheckrc 中配置 disable=SC2086 以在项目范围内抑制。
ShellCheck 能发现安全问题吗?
ShellCheck 可以检测一些与安全相关的模式,如未引用的变量,但它不是安全扫描器。进行漏洞评估时请使用专用安全工具。
如何将 ShellCheck 与我的编辑器集成?
大多数编辑器都有 ShellCheck 插件:VS Code(vscode-shellcheck)、Sublime Text、Vim(ale 插件)、Emacs(flycheck)。这些提供实时反馈。

开发者详情

文件结构

📄 SKILL.md