[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-b576a244-7f66-425e-b38a-8585e4f832f0":3,"$fBgUCSO9vnvMYL_s8f3Rybp_hjwAeGSM8Hpvs_yh6db4":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"b576a244-7f66-425e-b38a-8585e4f832f0","shellcheck-configuration","掌握ShellCheck静态分析配置和使用，以提升shell脚本质量。在设置代码检查基础设施、修复代码问题或确保脚本可移植性时使用。","cat_life_career","mod_other","sickn33,other","---\nname: shellcheck-configuration\ndescription: \"Master ShellCheck static analysis configuration and usage for shell script quality. Use when setting up linting infrastructure, fixing code issues, or ensuring script portability.\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n# ShellCheck Configuration and Static Analysis\n\nComprehensive guidance for configuring and using ShellCheck to improve shell script quality, catch common pitfalls, and enforce best practices through static code analysis.\n\n## Do not use this skill when\n\n- The task is unrelated to shellcheck configuration and static analysis\n- You need a different domain or tool outside this scope\n\n## Instructions\n\n- Clarify goals, constraints, and required inputs.\n- Apply relevant best practices and validate outcomes.\n- Provide actionable steps and verification.\n- If detailed examples are required, open `resources\u002Fimplementation-playbook.md`.\n\n## Use this skill when\n\n- Setting up linting for shell scripts in CI\u002FCD pipelines\n- Analyzing existing shell scripts for issues\n- Understanding ShellCheck error codes and warnings\n- Configuring ShellCheck for specific project requirements\n- Integrating ShellCheck into development workflows\n- Suppressing false positives and configuring rule sets\n- Enforcing consistent code quality standards\n- Migrating scripts to meet quality gates\n\n## ShellCheck Fundamentals\n\n### What is ShellCheck?\n\nShellCheck is a static analysis tool that analyzes shell scripts and detects problematic patterns. It supports:\n- Bash, sh, dash, ksh, and other POSIX shells\n- Over 100 different warnings and errors\n- Configuration for target shell and flags\n- Integration with editors and CI\u002FCD systems\n\n### Installation\n\n```bash\n# macOS with Homebrew\nbrew install shellcheck\n\n# Ubuntu\u002FDebian\napt-get install shellcheck\n\n# From source\ngit clone https:\u002F\u002Fgithub.com\u002Fkoalaman\u002Fshellcheck.git\ncd shellcheck\nmake build\nmake install\n\n# Verify installation\nshellcheck --version\n```\n\n## Configuration Files\n\n### .shellcheckrc (Project Level)\n\nCreate `.shellcheckrc` in your project root:\n\n```\n# Specify target shell\nshell=bash\n\n# Enable optional checks\nenable=avoid-nullary-conditions\nenable=require-variable-braces\n\n# Disable specific warnings\ndisable=SC1091\ndisable=SC2086\n```\n\n### Environment Variables\n\n```bash\n# Set default shell target\nexport SHELLCHECK_SHELL=bash\n\n# Enable strict mode\nexport SHELLCHECK_STRICT=true\n\n# Specify configuration file location\nexport SHELLCHECK_CONFIG=~\u002F.shellcheckrc\n```\n\n## Common ShellCheck Error Codes\n\n### SC1000-1099: Parser Errors\n```bash\n# SC1004: Backslash continuation not followed by newline\necho hello\\\nworld  # Error - needs line continuation\n\n# SC1008: Invalid data for operator `=='\nif [[ $var =  \"value\" ]]; then  # Space before ==\n    true\nfi\n```\n\n### SC2000-2099: Shell Issues\n\n```bash\n# SC2009: Consider using pgrep or pidof instead of grep|grep\nps aux | grep -v grep | grep myprocess  # Use pgrep instead\n\n# SC2012: Use `ls` only for viewing. Use `find` for reliable output\nfor file in $(ls -la)  # Better: use find or globbing\n\n# SC2015: Avoid using && and || instead of if-then-else\n[[ -f \"$file\" ]] && echo \"found\" || echo \"not found\"  # Less clear\n\n# SC2016: Expressions don't expand in single quotes\necho '$VAR'  # Literal $VAR, not variable expansion\n\n# SC2026: This word is non-standard. Set POSIXLY_CORRECT\n# when using with scripts for other shells\n```\n\n### SC2100-2199: Quoting Issues\n\n```bash\n# SC2086: Double quote to prevent globbing and word splitting\nfor i in $list; do  # Should be: for i in $list or for i in \"$list\"\n    echo \"$i\"\ndone\n\n# SC2115: Literal tilde in path not expanded. Use $HOME instead\n~\u002F.bashrc  # In strings, use \"$HOME\u002F.bashrc\"\n\n# SC2181: Check exit code directly with `if`, not indirectly in a list\nsome_command\nif [ $? -eq 0 ]; then  # Better: if some_command; then\n\n# SC2206: Quote to prevent word splitting or set IFS\narray=( $items )  # Should use: array=( $items )\n```\n\n### SC3000-3999: POSIX Compliance Issues\n\n```bash\n# SC3010: In POSIX sh, use 'case' instead of 'cond && foo'\n[[ $var == \"value\" ]] && do_something  # Not POSIX\n\n# SC3043: In POSIX sh, use 'local' is undefined\nfunction my_func() {\n    local var=value  # Not POSIX in some shells\n}\n```\n\n## Practical Configuration Examples\n\n### Minimal Configuration (Strict POSIX)\n\n```bash\n#!\u002Fbin\u002Fbash\n# Configure for maximum portability\n\nshellcheck \\\n  --shell=sh \\\n  --external-sources \\\n  --check-sourced \\\n  script.sh\n```\n\n### Development Configuration (Bash with Relaxed Rules)\n\n```bash\n#!\u002Fbin\u002Fbash\n# Configure for Bash development\n\nshellcheck \\\n  --shell=bash \\\n  --exclude=SC1091,SC2119 \\\n  --enable=all \\\n  script.sh\n```\n\n### CI\u002FCD Integration Configuration\n\n```bash\n#!\u002Fbin\u002Fbash\nset -Eeuo pipefail\n\n# Analyze all shell scripts and fail on issues\nfind . -type f -name \"*.sh\" | while read -r script; do\n    echo \"Checking: $script\"\n    shellcheck \\\n        --shell=bash \\\n        --format=gcc \\\n        --exclude=SC1091 \\\n        \"$script\" || exit 1\ndone\n```\n\n### .shellcheckrc for Project\n\n```\n# Shell dialect to analyze against\nshell=bash\n\n# Enable optional checks\nenable=avoid-nullary-conditions,require-variable-braces,check-unassigned-uppercase\n\n# Disable specific warnings\n# SC1091: Not following sourced files (many false positives)\ndisable=SC1091\n\n# SC2119: Use function_name instead of function_name -- (arguments)\ndisable=SC2119\n\n# External files to source for context\nexternal-sources=true\n```\n\n## Integration Patterns\n\n### Pre-commit Hook Configuration\n\n```bash\n#!\u002Fbin\u002Fbash\n# .git\u002Fhooks\u002Fpre-commit\n\n#!\u002Fbin\u002Fbash\nset -e\n\n# Find all shell scripts changed in this commit\ngit diff --cached --name-only | grep '\\.sh$' | while read -r script; do\n    echo \"Linting: $script\"\n\n    if ! shellcheck \"$script\"; then\n        echo \"ShellCheck failed on $script\"\n        exit 1\n    fi\ndone\n```\n\n### GitHub Actions Workflow\n\n```yaml\nname: ShellCheck\n\non: [push, pull_request]\n\njobs:\n  shellcheck:\n    runs-on: ubuntu-latest\n\n    steps:\n      - uses: actions\u002Fcheckout@v3\n\n      - name: Run ShellCheck\n        run: |\n          sudo apt-get install shellcheck\n          find . -type f -name \"*.sh\" -exec shellcheck {} \\;\n```\n\n### GitLab CI Pipeline\n\n```yaml\nshellcheck:\n  stage: lint\n  image: koalaman\u002Fshellcheck-alpine\n  script:\n    - find . -type f -name \"*.sh\" -exec shellcheck {} \\;\n  allow_failure: false\n```\n\n## Handling ShellCheck Violations\n\n### Suppressing Specific Warnings\n\n```bash\n#!\u002Fbin\u002Fbash\n\n# Disable warning for entire line\n# shellcheck disable=SC2086\nfor file in $(ls -la); do\n    echo \"$file\"\ndone\n\n# Disable for entire script\n# shellcheck disable=SC1091,SC2119\n\n# Disable multiple warnings (format varies)\ncommand_that_fails() {\n    # shellcheck disable=SC2015\n    [ -f \"$1\" ] && echo \"found\" || echo \"not found\"\n}\n\n# Disable specific check for source directive\n# shellcheck source=.\u002Fhelper.sh\nsource helper.sh\n```\n\n### Common Violations and Fixes\n\n#### SC2086: Double quote to prevent word splitting\n\n```bash\n# Problem\nfor i in $list; do done\n\n# Solution\nfor i in $list; do done  # If $list is already quoted, or\nfor i in \"${list[@]}\"; do done  # If list is an array\n```\n\n#### SC2181: Check exit code directly\n\n```bash\n# Problem\nsome_command\nif [ $? -eq 0 ]; then\n    echo \"success\"\nfi\n\n# Solution\nif some_command; then\n    echo \"success\"\nfi\n```\n\n#### SC2015: Use if-then instead of && ||\n\n```bash\n# Problem\n[ -f \"$file\" ] && echo \"exists\" || echo \"not found\"\n\n# Solution - clearer intent\nif [ -f \"$file\" ]; then\n    echo \"exists\"\nelse\n    echo \"not found\"\nfi\n```\n\n#### SC2016: Expressions don't expand in single quotes\n\n```bash\n# Problem\necho 'Variable value: $VAR'\n\n# Solution\necho \"Variable value: $VAR\"\n```\n\n#### SC2009: Use pgrep instead of grep\n\n```bash\n# Problem\nps aux | grep -v grep | grep myprocess\n\n# Solution\npgrep -f myprocess\n```\n\n## Performance Optimization\n\n### Checking Multiple Files\n\n```bash\n#!\u002Fbin\u002Fbash\n\n# Sequential checking\nfor script in *.sh; do\n    shellcheck \"$script\"\ndone\n\n# Parallel checking (faster)\nfind . -name \"*.sh\" -print0 | \\\n    xargs -0 -P 4 -n 1 shellcheck\n```\n\n### Caching Results\n\n```bash\n#!\u002Fbin\u002Fbash\n\nCACHE_DIR=\".shellcheck_cache\"\nmkdir -p \"$CACHE_DIR\"\n\ncheck_script() {\n    local script=\"$1\"\n    local hash\n    local cache_file\n\n    hash=$(sha256sum \"$script\" | cut -d' ' -f1)\n    cache_file=\"$CACHE_DIR\u002F$hash\"\n\n    if [[ ! -f \"$cache_file\" ]]; then\n        if shellcheck \"$script\" > \"$cache_file\" 2>&1; then\n            touch \"$cache_file.ok\"\n        else\n            return 1\n        fi\n    fi\n\n    [[ -f \"$cache_file.ok\" ]]\n}\n\nfind . -name \"*.sh\" | while read -r script; do\n    check_script \"$script\" || exit 1\ndone\n```\n\n## Output Formats\n\n### Default Format\n\n```bash\nshellcheck script.sh\n\n# Output:\n# script.sh:1:3: warning: foo is referenced but not assigned. [SC2154]\n```\n\n### GCC Format (for CI\u002FCD)\n\n```bash\nshellcheck --format=gcc script.sh\n\n# Output:\n# script.sh:1:3: warning: foo is referenced but not assigned.\n```\n\n### JSON Format (for parsing)\n\n```bash\nshellcheck --format=json script.sh\n\n# Output:\n# [{\"file\": \"script.sh\", \"line\": 1, \"column\": 3, \"level\": \"warning\", \"code\": 2154, \"message\": \"...\"}]\n```\n\n### Quiet Format\n\n```bash\nshellcheck --format=quiet script.sh\n\n# Returns non-zero if issues found, no output otherwise\n```\n\n## Best Practices\n\n1. **Run ShellCheck in CI\u002FCD** - Catch issues before merging\n2. **Configure for your target shell** - Don't analyze bash as sh\n3. **Document exclusions** - Explain why violations are suppressed\n4. **Address violations** - Don't just disable warnings\n5. **Enable strict mode** - Use `--enable=all` with careful exclusions\n6. **Update regularly** - Keep ShellCheck current for new checks\n7. **Use pre-commit hooks** - Catch issues locally before pushing\n8. **Integrate with editors** - Get real-time feedback during development\n\n## Resources\n\n- **ShellCheck GitHub**: https:\u002F\u002Fgithub.com\u002Fkoalaman\u002Fshellcheck\n- **ShellCheck Wiki**: https:\u002F\u002Fwww.shellcheck.net\u002Fwiki\u002F\n- **Error Code Reference**: https:\u002F\u002Fwww.shellcheck.net\u002F\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,80,1280,"2026-05-16 13:40:18",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"其他","other","mdi-page-next-outline","其他类型Skill",5,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"职场发展","career","mdi-briefcase-outline","面试准备、简历优化、职业规划",4,575,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"6ade6bbc-2650-4c07-bc93-36abfcb10d99","1.0.0","shellcheck-configuration.zip",4088,"uploads\u002Fskills\u002Fb576a244-7f66-425e-b38a-8585e4f832f0\u002Fshellcheck-configuration.zip","fa39e72f83a7325f45f52f9a655a705bb0a22f51e7095eee3b21c2c0660b4319","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":10297}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]