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.
68
83%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Treat a clean ShellCheck run as the floor, never the ceiling, of validation. ShellCheck is a static analyzer: it never executes the script, so it cannot catch a missing file, a wrong permission, or an exit code that only shows up under a real workload. Always run the script against representative inputs, in a sandbox or container, after ShellCheck passes — not instead of it. Never accept a blanket # shellcheck disable=SCxxxx at the top of a file; a global suppression hides every future violation of that rule, not just the one the author intended to silence. Verify the shebang matches the actual syntax used in the body before trusting either signal alone: a #!/bin/sh script written with bash-only syntax ([[ ]], declare -A) will pass a naive bash-mode check and then fail silently on Alpine, BusyBox, or any strict POSIX sh. Check exit-code propagation explicitly — a function that swallows a real failure with || true or an unconditional exit 0 breaks set -e for every caller upstream of it, and that failure mode does not show up in ShellCheck's output at all.
Use this skill when validating an existing bash or POSIX sh script, running ShellCheck against a script and interpreting its output, auditing a script for security issues (command injection, unsafe eval, unquoted expansions), checking whether a script marked #!/bin/sh is actually POSIX-compliant, or debugging why a script behaves differently across environments.
Do not use this skill to write a new script from scratch — that is the bash-script-generator skill's job; this one only validates and explains, it does not author the initial structure. Do not use it for scripts in a different language interpreted by a shebang (Python, Perl, Ruby) — those need their own linters, not ShellCheck or bash-specific portability checks.
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 # FedoraOption 2: Automatic via Wrapper (Python required)
./scripts/shellcheck_wrapper.sh --cache script.sh
# Clears cache: ./scripts/shellcheck_wrapper.sh --clear-cacheOption 3: Manual Python install
pip3 install shellcheck-pyThe 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.a1083f4
Also appears in
last in sync Aug 28, 2026
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.