- Home
- Skills
- APIs & Backend
- Safe Bash Script Template Generator
Works with the AI Agents you already use
Safe Bash Script Template Generator
by Saizul Amin
Generate production-ready Bash/POSIX scripts with strict error handling, argument parsing, and dry-run safety.
Free
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
- Fix the highest-severity items first.
- Ask your agent to apply the fixes it suggests, then run the skill again to confirm.
- 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
EXITtraps for temp directory cleanup andERRtraps 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
flockor directory-based locking for macOS compatibility.
How it works
- Define the interface: Specify the script name, arguments, flags, and whether you need Bash or POSIX
sh. - Execute the generator: Run the internal Python helper to produce the shell script skeleton.
- Implement logic: Add your commands to the
main()function, wrapping mutations in the providedrunhelper for dry-run support. - Validation: Run syntax checks and test the generated
--helpoutput 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
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
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 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
Trust & safety
Security scan
Security scan passed 2 days ago
- Free with an Agensi account
- Software
Python 3.8+