skills/development/scripting/bash-script/validator/SKILL.md
Comprehensive toolkit for validating, linting, and optimizing bash and shell scripts. Use this skill when working with shell scripts (.sh, .bash), validating script syntax, detecting unquoted variables, checking POSIX compliance, identifying unsafe command substitutions, validating shebang lines, finding security vulnerabilities, or debugging shell script problems.
npx skillsauth add pantheon-org/tekhne bash-script-validatorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
bash scripts/validate.sh <script-path>
1. Run: bash scripts/validate.sh <script-path>
2. Read the validation output and identify all issues
3. Read references/common-mistakes.md for fix patterns
4. Read references/shellcheck-reference.md for SC error explanations (if needed)
5. For EACH issue found:
a. Show the problematic code
b. Explain the issue (referencing documentation)
c. Provide the corrected code
d. Explain why the fix improves the script
========================================
BASH/SHELL SCRIPT VALIDATOR
========================================
File: myscript.sh
Detected Shell: bash
[SYNTAX CHECK]
✓ No syntax errors found (bash -n)
[SHELLCHECK]
myscript.sh:15:5: warning: Quote to prevent word splitting [SC2086]
myscript.sh:23:9: error: Use || exit to handle cd failure [SC2164]
[CUSTOM CHECKS]
⚠ Potential command injection: eval with variable found
Line 42: eval $user_input
ℹ Useless use of cat detected
Line 18: cat file.txt | grep pattern
========================================
VALIDATION SUMMARY
========================================
Errors: 2
Warnings: 3
Info: 1
## Validation Results
Found X errors, Y warnings, Z info issues.
### Issue 1: Unquoted Variable (Line 25)
**Problem:**
\`\`\`bash
if [ ! -f $file ]; then # Word splitting risk
\`\`\`
**Reference:** See `common-mistakes.md` section "1. Unquoted Variables"
**Fix:**
\`\`\`bash
if [ ! -f "$file" ]; then # Properly quoted
\`\`\`
**Why:** Unquoted variables undergo word splitting and glob expansion,
causing unexpected behavior with filenames containing spaces or special characters.
Located in assets/ directory:
Option 1: System-wide (Recommended)
brew install shellcheck # macOS
apt-get install shellcheck # Ubuntu/Debian
dnf install shellcheck # Fedora
Option 2: Automatic via Wrapper (Python required)
./scripts/shellcheck_wrapper.sh --cache script.sh
# Clears cache: ./scripts/shellcheck_wrapper.sh --clear-cache
Option 3: Manual Python install
pip3 install shellcheck-py
The validator works without ShellCheck but provides enhanced validation when available.
#!/bin/bash, #!/usr/bin/env bash → bash#!/bin/sh, #!/usr/bin/sh → POSIX sh#!/bin/zsh → zsh / #!/bin/ksh → ksh / #!/bin/dash → dashbash -n or sh -neval, command injection, rm -rf, unquoted variablesbash-script-validator/
├── scripts/validate.sh
├── references/ # bash, shell, shellcheck, common-mistakes, grep, awk, sed, regex
└── assets/ # good-bash.sh, bad-bash.sh, good-shell.sh, bad-shell.sh
# shellcheck disable=SCxxxx at the top of a file defeats the purpose of linting and silently hides real issues in code added later, long after the original suppression rationale is forgotten.# shellcheck disable=SC2086 at the top of the file to silence all quoting warnings across every line in the script.# shellcheck disable=SC2086 # word splitting intentional here.[[ ]], $(()) arithmetic, or many bash extensions; scripts marked #!/bin/sh will fail with bash-only syntax on some systems (Alpine Linux, minimal containers, many CI runners).#!/bin/sh as the shebang but write bash-specific syntax like declare -A or [[ -n $var ]] — the script will fail silently or with cryptic errors on non-bash sh implementations.#!/usr/bin/env bash for scripts that require bash features; use #!/bin/sh only for scripts that are tested with strict POSIX compliance using shellcheck --shell=sh.exit 0 or || true to suppress error propagationset -e propagation, and makes debugging silent failures much harder.validate() { run_check || true; return 0; } — the function always succeeds even when run_check fails, so callers cannot detect the failure.set -e propagate failures: validate() { run_check; } — if run_check fails, validate fails, and the caller can act on the exit code.tools
A skill that produces warnings but no errors.
testing
A well-formed example skill for testing the validator.
development
A skill with code blocks and imperative instructions for testing content and contamination analysis.
tools