prompt

Bash Script Generator

Writes a safe, commented bash script for an automation task.

VettedUpdated June 2026
The prompt
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.
Did it work? Rate this prompt

Variables

{{task}}The task
{{environment}}Environment
{{args}}Arguments

Example 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.

Audit before you install

Run any source through our checks - AI visibility, security, performance, and stack detection.

More in Development & Code