prompt
Bash Script Generator
Writes a safe, commented bash script for an automation task.
You are a shell scripting expert. Write a bash script for the task below. Inputs: - The task: {{task}} - Environment: {{environment}} (OS, tools available) - Inputs/arguments the script takes: {{args}} Produce: 1. A complete, commented script starting with a shebang and safe options (set -euo pipefail). 2. Argument parsing + a usage/help message if {{args}} are involved. 3. Input validation and clear error messages (fail loudly, not silently). 4. The core logic, commented at each non-obvious step. 5. A one-line "how to run it" example. Rules: quote variables ("$var") to handle spaces; check that required commands/files exist before using them; never run destructive commands (rm -rf, etc.) without an explicit confirmation or a dry-run flag; avoid parsing ls; flag anything that needs elevated privileges. If {{task}} touches production or deletion, add a confirmation prompt.
Variables
{{task}}The task{{environment}}Environment{{args}}ArgumentsExample output
Task: back up a directory to a timestamped tar.gz. Args: source dir, destination dir. #!/usr/bin/env bash set -euo pipefail usage() { echo "Usage: $0 <source_dir> <dest_dir>"; exit 1; } [ "$#" -eq 2 ] || usage SRC="$1"; DEST="$2" # Validate inputs before doing anything [ -d "$SRC" ] || { echo "Error: source '$SRC' is not a directory" >&2; exit 1; } mkdir -p "$DEST" STAMP="$(date +%Y%m%d_%H%M%S)" ARCHIVE="$DEST/backup_$STAMP.tar.gz" # Create the archive; tar handles the recursion tar -czf "$ARCHIVE" -C "$SRC" . echo "Backup created: $ARCHIVE" Run it: ./backup.sh /var/www/myapp /backups Note: this only reads the source and writes a new archive \u2014 nothing is deleted. Add a retention/cleanup step separately, with a confirmation, if you want old backups removed.
Details
Author
AI Khazna
License
—
Security
Vetted
Type
prompt
Related assets
More curated picks in Development & Code.
npm install @modelcontextprotocol/server-everything
npm install @modelcontextprotocol/server-memory
npm install @modelcontextprotocol/server-filesystem
npm install @modelcontextprotocol/server-git
npm install @modelcontextprotocol/server-fetch
npm install @modelcontextprotocol/server-sequentialthinking
Audit before you install
Run any source through our checks - AI visibility, security, performance, and stack detection.
Automated Web Security Scan
security
PageSpeed Analyzer
performance
AI Content Quality Test
arabic content
AI Agent / MCP Server Tester
ai testing
Site Stack Detector
migration
AI SEO / AEO / GEO Audit
ai visibility
llms.txt Generator
ai visibility
Readability Score
arabic content
Schema / JSON-LD Builder
ai visibility
AI Cost Calculator
ai testing
Headline Analyzer
arabic content