技能 shellcheck-configuration
📦

shellcheck-configuration

安全

為 Shell 腳本品質配置 ShellCheck

也可從以下取得: wshobson

Shell 腳本通常包含難以手動發現的細微錯誤和可移植性問題。本技能提供綜合指導,說明如何配置和使用 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 腳本中的錯誤、警告和問題。它支援 Bash、sh、dash、ksh 和其他 POSIX shells。
如何安裝 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