Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+22 more

    Safe Bash Script Template Generator

    by Saizul Amin

    1

    Generate production-ready Bash/POSIX scripts with strict error handling, argument parsing, and dry-run safety.

    Free

    Security scanned
    Safe Bash Script Template Generator

    Safe Bash Script Template Generator

    Example session with this skill installed

    Run the Safe Bash Script Template Generator skill on my project and give me a prioritised list of what to fix, with exact changes.

    • Read your context and instructions
    • Compiled the safe bash script

    Here is what the Safe Bash Script Template Generator skill produced.

    Demo: real, unedited output of the skill's bundled script on a sample input from its test suite.

    Output

    #!/usr/bin/env bash
    
    # x: Describe what this script does.
    #
    
    # Generated from the bash-script-template skill. Edit main() and keep the safety rails.
    set -Eeuo pipefail
    shopt -s inherit_errexit 2>/dev/null || true
    
    SCRIPT_NAME="$(basename -- "${BASH_SOURCE[0]}")"
    readonly SCRIPT_NAME
    SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
    readonly SCRIPT_DIR
    
    # ----- defaults
    DRY_RUN=0
    LOG_LEVEL="${LOG_LEVEL:-info}"
    FILE=""
    
    # ----- logging (stderr, so stdout stays clean for data)
    _log() {
      local level=$1; shift
      local -i want=1 have=1
      case $LOG_LEVEL in debug) want=0 ;; info) want=1 ;; warn) want=2 ;; error) want=3 ;; esac
      case $level in DEBUG) have=0 ;; INFO) have=1 ;; WARN) have=2 ;; ERROR) have=3 ;; esac
      if (( have >= want )); then
        printf '%s %-5s %s: %s\n' "$(date -u +%Y-%m-%dT%H:%M:%SZ)" "$level" "$SCRIPT_NAME" "$*" >&2
      fi
    }
    debug() { _log DEBUG "$@"; }
    info() { _log INFO "$@"; }
    warn() { _log WARN "$@"; }
    die() { _log ERROR "$@"; exit 1; }
    usage_error() { printf '%s: %s\n' "$SCRIPT_NAME" "$*" >&2; printf 'Try %s --help\n' "$SCRIPT_NAME" >&2; exit 2; }
    
    # run CMD ARGS...: executes, or only prints with --dry-run. Pass arguments separately, never as one string.
    run() {
      if (( DRY_RUN )); then
        printf '[dry-run]' >&2; printf ' %q' "$@" >&2; printf '\n' >&2
      else
        debug "+ $*"
        "$@"
      fi
    }
    
    # ----- cleanup and error reporting
    TMP_DIR=""
    cleanup() {
      local status=$?
      if [[ -n $TMP_DIR && -d $TMP_DIR ]]; then rm -rf -- "${TMP_DIR:?}"; fi
      exit "$status"
    }
    on_error() {
      _log ERROR "failed at line $1: $2 (exit $3)"
    }
    trap cleanup EXIT
    trap 'on_error "$LINENO" "$BASH_COMMAND" "$?"' ERR
    trap 'exit 130' INT
    trap 'exit 143' TERM
    
    usage() {
      cat <<EOF
    Usage: $SCRIPT_NAME [options] FILE
    
    Describe what this script does.
    
    Arguments:
      FILE                   file
    
    Options:
      -n, --dry-run          print commands instead of running them
      -v, --verbose          debug logging (same as LOG_LEVEL=debug)
      -q, --quiet            only warnings and errors
      -h, --help             show this help
    
    Environment:
      LOG_LEVEL              debug, info (default), warn, error
    EOF
    }
    
    parse_args() {
      local positional=()
      while (( $# )); do
        case $1 in
          -h|--help) usage; exit 0 ;;
          -n|--dry-run) DRY_RUN=1 ;;
          -v|--verbose) LOG_LEVEL=debug ;;
          -q|--quiet) LOG_LEVEL=warn ;;
          --) shift; positional+=("$@"); break ;;
          -*) usage_error "unknown option: $1" ;;
          *) positional+=("$1") ;;
        esac
        shift
      done
      if (( ${#positional[@]} != 1 )); then
        usage_error "expected 1 argument(s), got ${#positional[@]}"
      fi
      FILE=${positional[0]}
    }
    
    main() {
      parse_args "$@"
      TMP_DIR="$(mktemp -d "${TMPDIR:-/tmp}/$SCRIPT_NAME.XXXXXX")"
      debug "script dir: $SCRIPT_DIR, temp dir: $TMP_DIR, dry-run: $DRY_RUN"
      info "file: $FILE"
    
      # TODO: replace with the real work. Use run for commands that change things:
      run touch -- "$TMP_DIR/example"
    
      info "done"
    }
    
    main "$@"
    

    What you do next

    1. Fix the highest-severity items first.
    2. Ask your agent to apply the fixes it suggests, then run the skill again to confirm.
    3. Keep the skill installed and re-run it whenever the project changes.

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

    About this skill

    Writing reliable shell scripts from memory usually leads to bugs in error handling, signal traps, and argument parsing. This skill generates a production-ready bash or POSIX sh skeleton that implements the boilerplate you usually skip, ensuring your automation is safe and predictable.

    What it does

    • Boilerplate generation: Scaffolds scripts with strict mode (set -Eeuo pipefail) and standard exit codes.
    • Argument parsing: Generates logic for short/long options, flags, and required positional arguments.
    • Safety features: Implements EXIT traps for temp directory cleanup and ERR traps for line-number reporting.
    • Operational controls: Built-in support for --dry-run, --verbose, --help, and leveled logging to stderr.
    • Concurrency locking: Optional single-instance protection using flock or directory-based locking for macOS compatibility.

    How it works

    1. Define the interface: Specify the script name, arguments, flags, and whether you need Bash or POSIX sh.
    2. Execute the generator: Run the internal Python helper to produce the shell script skeleton.
    3. Implement logic: Add your commands to the main() function, wrapping mutations in the provided run helper for dry-run support.
    4. Validation: Run syntax checks and test the generated --help output before deployment.

    Frameworks & tools

    The generator requires Python 3.8+ for execution. Generated scripts are compatible with Bash 3.2+ (standard on macOS) or any POSIX-compliant shell.

    Why this beats prompting it yourself

    Generic LLM prompts often produce scripts that lack proper quoting, ignore pipe failures, or miss crucial cleanup traps. This skill enforces a consistent, battle-tested structure that passes ShellCheck by default and handles edge cases like option-value pairing (--key value vs --key=value) correctly every time.

    Use cases

    • Scaffold a CLI wrapper for complex toolchains with help menus and flags.
    • Create automated backup or deployment scripts with mandatory dry-run safety.
    • Convert raw README commands into a reusable, logged, and trapped maintenance script.
    • Build Docker healthcheck scripts using the lightweight POSIX sh mode.

    Known limitations

    Does not support complex data structures or HTTP/JSON processing; use Python for those. Not designed for reviewing existing scripts.


    Open source: saizul/bash-shell-skills on GitHub (MIT licence, by Saizul Amin).

    Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for APIs & Backend.

    Requires Python 3.8+ to run the generator. Not suitable for scripts requiring complex data structures or heavy API interactions. Does not lint existing scripts.

    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

    Free to use

    No account required to browse

    Frequently Asked Questions

    This skill generates a robust, production-ready script skeleton including strict error handling, argument parsing, and safety features that manual coding often overlooks. It saves you from common pitfalls like missing cleanup traps or improper quoting that lead to script failures in production.

    The skill can generate scripts for either modern Bash (3.2+) or strict POSIX sh. This makes it ideal for everything from feature-rich CLI tools on macOS and Linux to ultra-lightweight automation for Docker containers and embedded systems.

    The generated scripts include a built-in 'run' helper function. When you wrap your commands in this helper, they will automatically be skipped when the script is executed with the --dry-run flag, allowing you to test logic safely without making changes.

    While the generated scripts are standalone shell files, the generator itself requires Python 3.8+ to run. It does not require any external shell libraries or third-party dependencies to execute the final scripts once they are created.

    The skill is designed to create a structured 'main()' function and boilerplate logic for new scripts. It is not currently optimized for analyzing or refactoring your existing, pre-written shell scripts.

    Yes, the generated templates are intentionally designed to pass ShellCheck's rigorous linting rules by default. This ensures your scripts follow industry best practices for security and performance from the very first line.

    New in APIs & Backend

    Free