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
Frequently asked questions
What is the Bash Script Generator prompt?
Writes a safe, commented bash script for an automation task.
Is Bash Script Generator free?
Yes, it is free to use.
Related assets
More curated picks in Development & Code.
Refactors code for readability and structure while preserving behavior, with rationale.
Turns a bug report into a structured debugging plan with hypotheses and checks to isolate the cause.
Reviews a code diff or snippet for bugs, security, readability, and edge cases.
Generates unit tests for a function, including edge cases and failure paths.
Writes a clear PR description with summary, changes, testing, and review notes from a diff or change list.
Writes docstrings, inline comments, and README sections for existing code.
Audit before you install
Run any source through our checks - AI visibility, security, performance, and stack detection.
AI Agent / MCP Server Tester
ai testing
Automated Web Security Scan
security
AI Content Quality Test
arabic content
Site Stack Detector
migration
PageSpeed Analyzer
performance
AI SEO / AEO / GEO Audit
ai visibility
llms.txt Generator
ai visibility
Schema / JSON-LD Builder
ai visibility
Readability Score
arabic content
AI Cost Calculator
ai testing
Headline Analyzer
arabic content