Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Bash Script Hardener with ShellCheck and Bats Tests

    1

    Hardens or writes bash and sh scripts with ShellCheck, quoting, safe rm, traps, getopts, dry-run and macOS fixes, plus tests. Verdict SAFE / FIX FIRST / DANGEROUS

    $5

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Bash Script Hardener with ShellCheck and Bats Tests

    Bash Script Hardener with ShellCheck and Bats Tests

    Example session with this skill installed

    Harden this cron script before I deploy it. It prunes old backups and runs on an Ubuntu server and on my MacBook:

    #!/bin/bash
    BACKUP_DIR=$1
    DAYS=7

    cd $BACKUP_DIR
    for f in $(ls *.tar.gz); do
      if [ $(find $f -mtime +$DAYS) ]; then rm -rf $f; fi
    done
    rm -rf $BACKUP_DIR/tmp/*
    sed -i "s/last_run=.*/last_run=$(date -d now +%F)/" state.conf
    
    • Read your context and instructions
    • Compiled the bash script hardener

    Verdict

    Original: DANGEROUS: with no argument, cd $BACKUP_DIR goes to $HOME and line 8 runs rm -rf /tmp/*
    Corrected: SAFE: ShellCheck 0.11.0 clean, 11/11 tests pass (bash 5.2, Linux). macOS not run here.

    Findings

    #LineSeverityIssueCodeFix
    18DANGEROUSempty BACKUP_DIR becomes rm -rf /tmp/*manualrequire arg, resolve path, "${BACKUP_DIR:?}/tmp"
    24HIGHunchecked, unquoted cdSC2164, SC2086no cd; absolute path, refuse /
    35HIGHloop over ls outputSC2045, SC2035find -print0 + read -r -d ''
    46MEDunquoted $(find ...) in [ ]SC2046, SC2086find -mtime +"$DAYS" does the test
    59MEDsed -i, date -d are GNU-onlymanualsed > "$tmp/x" && mv; date +%Y-%m-%d
    6allLOWno usage, dry-run, logging, exit codesmanualgetopts, -n/--dry-run, log() to stderr

    Corrected script (excerpt; full file delivered)

    #!/usr/bin/env bash
    set -Eeuo pipefail
    ...
    (( $# == 1 )) || { usage >&2; exit 2; }
    BACKUP_DIR=$(cd -P -- "$1" && pwd -P)
    [[ $BACKUP_DIR != / ]] || die "refusing to prune /"
    tmp=$(mktemp -d "${TMPDIR:-/tmp}/${SCRIPT_NAME}.XXXXXX")
    trap cleanup EXIT
    while IFS= read -r -d '' f; do
      run rm -f -- "$f"; count=$((count + 1))
    done < <(find "$BACKUP_DIR" -maxdepth 1 -type f \
      -name '*.tar.gz' -mtime +"$DAYS" -print0)
    

    Diff summary

    • Safety: path is required, resolved and checked; no rm -rf on a bare variable
    • Portability: no sed -i / date -d; works with macOS bash 3.2
    • Behavior changes: new -d DAYS, -n/--dry-run, -h; exit 2 on bad usage

    Tests

    test/run-tests.sh (bats not installed): 11 passed, 0 failed, including a dry run that leaves files in place and a backup name with a space.

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Most shell scripts work right up until a variable is empty, a filename has a space, or the script runs on a Mac. Then rm -rf hits the wrong directory, a cron job fails silently, or sed -i errors on BSD. Asking an AI to "review my script" usually gets a list of tips, not a fixed file you can trust.

    This skill gives your coding agent a fixed procedure and a reference file of checked facts. It:

    • Checks for dangerous patterns first: unguarded rm -rf on variable paths, curl piped to bash, eval or sh -c on input, secrets in argv or set -x output
    • Runs ShellCheck and shfmt if installed, or works through a manual checklist and says so
    • Fixes strict mode (and notes where set -e will not fire), quoting, [[ ]] vs [ ], mktemp with EXIT/INT/TERM traps, ${VAR:?} guards, getopts with usage, --dry-run, stderr logging, exit codes, idempotency and safe file reading
    • Flags GNU vs BSD differences (sed -i, date -d, readlink -f, stat) and bash 4+ features that break on macOS /bin/bash 3.2
    • Returns the full corrected script, a findings table with line numbers, a diff summary, and a bats test file (or a plain bash test script if bats is not installed)
    • Gives a verdict on both the original and the corrected file: SAFE, FIX FIRST or DANGEROUS

    For developers, DevOps and SRE engineers, and anyone who writes cron jobs, CI steps, install scripts or container entrypoints.

    The ShellCheck codes, tool versions and macOS facts in the reference file were checked against the ShellCheck wiki, release pages and bats-core docs in October 2026. The skill only cites a code if ShellCheck reported it or it is listed in the reference. It reports test results only when it actually ran them.

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Code Quality & Review.

    Covers bash and POSIX sh only. It flags macOS and BusyBox differences but can only test on the system your agent runs on. ShellCheck and bats results depend on those tools being installed; without them, checks are manual and labeled as such. It does not replace a security audit of what the script's commands do.

    How to use

    1. 1

      Connect your agent to the Agensi MCP

      Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup

    2. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 3

      Ask for what you need

      Your agent loads this skill and uses it on your task. It always asks before buying a skill.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill goes through the trust checks below.

    Security scanned

    Checked by our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    Money-back guarantee

    Doesn't do what its page promises? You get your money back.

    Trust & safety

    Security scan

    Security scan passed 1 month ago

    Software
    BashGit
    Optional
    ShellCheckshfmtbats-core

    Without ShellCheck and shfmt, the skill checks by hand.

    Permissions

    Terminal / Shell
    Network Access
    Read Files
    Write Files
    Listed1 month ago

    What's inside

    Frequently Asked Questions

    Two files: SKILL.md (the procedure, verdict rules, output template and guardrails) and references/shell-hardening-facts.md (ShellCheck codes, set -e pitfalls, GNU vs BSD table, bash 3.2 limits, snippets for logging, traps, getopts and dry-run, and bats and plain test templates).

    Any agent that reads SKILL.md skills, such as Claude Code, Codex CLI, Cursor, VS Code Copilot and Gemini CLI. Put the folder in your agent's skills directory.

    No, but results are better with them. Without ShellCheck the agent uses a manual checklist and labels those findings as manual. Without bats it writes a plain bash test script. It suggests install commands but does not install anything without asking.

    It covers bash and POSIX sh, not zsh, fish or PowerShell. It cannot test on macOS if your agent runs on Linux, so it flags portability issues but marks them untested. Very long or data-heavy scripts may be better rewritten in another language; it will say so.

    It checks for destructive and injection patterns before style, uses a fixed fix order and checklist, cites only real ShellCheck codes, always returns a full corrected file plus tests, and gives a verdict for both the original and the corrected version.

    New in Code Quality & Review