Bash Script Generator Prompt
Generate a readable Bash script from a verified task, environment, inputs, and safety constraints, with validation, dry-run behavior, error handling, and rollback guidance.
Prompt Template
You are a senior shell programmer generating a Bash script only from the task, environment, and exact targets I supply. Resolve material ambiguity before writing a mutating script. Prefer explicit paths, previews, idempotent operations, least privilege, and readable control flow over compressed one-liners. Task and success criteria: [details] Operating system and version: [details] Bash version and invocation method: [details] Working directory: [exact verified path] Inputs, formats, and representative sanitized examples: [details] Expected outputs and destination paths: [exact details] Files, directories, hosts, services, or processes in scope: [exact identifiers] Targets that must never be touched: [list] Existing state and read-only inspection output: [paste] Required commands and verified installed versions: [list] Permissions available: [regular user, approved sudo for a named step, other] Network access and remote-host rules: [details] Concurrency, file-size, runtime, and portability constraints: [details] Whitespace, newline, encoding, glob, symlink, and hidden-file behavior: [details] Secrets and personal data handling: [describe placeholders; never paste values] Dry-run or preview requirement: [yes, no, tool-specific behavior] Logging and exit-code requirements: [details] Backup, rollback, and interruption requirements: [details] Existing script or style rules: [paste or none] Provide: 1. A requirements inventory separating verified inputs, assumptions, unresolved blockers, side effects, and success checks. 2. Read-only commands to confirm the Bash version, dependencies, paths, permissions, disk space, and target scope. 3. One complete, formatted Bash script with a usage message, quoted variables, input validation, meaningful functions, comments for non-obvious logic, and explicit exit behavior. 4. A dry-run mode that previews the exact targets and actions when any write, move, deletion, permission change, remote call, or service action is involved. 5. Safe temporary-file and cleanup handling, plus signals or traps only when the task requires them. 6. Error handling appropriate to the commands used; explain any set options instead of assuming they make every pipeline safe. 7. A test plan using a temporary fixture or non-production environment, including spaces, empty input, duplicate runs, partial failure, and interrupted execution. 8. Validation commands that confirm the requested result without relying only on the script's success message. 9. Backup and rollback instructions before material changes, with limits stated when rollback is impossible. 10. A final audit for unresolved placeholders, word splitting, unsafe eval, injection, broad globs, command substitution, symlink races, secrets, destructive recursion, privilege escalation, and portability. Do not invent paths, command flags, successful output, installed tools, credentials, or remote state. Never emit a destructive operation against an unresolved variable, wildcard, home directory, filesystem root, workspace root, or unverified recursive target. If the request cannot be made safe without a concrete path or policy choice, ask for it instead of generating runnable mutation code.
Example Output
Assumptions to Resolve
Replace the directory and age placeholders with verified values before running. The example only previews matches; it does not modify files.
#!/usr/bin/env bash
set -Eeuo pipefail
readonly scan_dir='[VERIFIED_DIRECTORY]'
readonly days='[DAYS_AS_INTEGER]'
if [[ ! -d "$scan_dir" || ! "$days" =~ ^[0-9]+$ ]]; then
printf 'Invalid directory or day count.\n' >&2
exit 2
fi
printf 'Preview only; matching files:\n'
find "$scan_dir" -type f -name '*.log' -mtime "+${days}" -print
Validation
Run `bash -n [SCRIPT_FILE]`, then test against a temporary fixture containing spaces and files on both sides of the age threshold. Inspect every printed path before adding any separate action.
Safety Note
No deletion, privilege escalation, network call, or successful result is claimed.
Tips for Best Results
- ๐กProvide exact paths, Bash version, sample inputs, and installed-command versions.
- ๐กRequire a preview mode and a temporary-fixture test before any material write.
- ๐กInspect quoting, globs, symlinks, traps, and partial-failure behavior instead of relying on one strict-mode line.
Frequently Asked Questions
What is the Bash Script Generator Prompt prompt?
Generate a readable Bash script from a verified task, environment, inputs, and safety constraints, with validation, dry-run behavior, error handling, and rollback guidance. It's a free ChatGPT prompt template from our Coding collection โ copy it, fill in the bracketed variables, and paste it into your AI tool.
Which AI tools work with this prompt?
It's written and tested for ChatGPT, Claude and Gemini. Any AI assistant that accepts free-form text prompts will handle it well.
How do I customize this ChatGPT prompt?
Replace the bracketed variables โ such as [details], [exact verified path], [exact details] โ with your own details before running it. Provide exact paths, Bash version, sample inputs, and installed-command versions.
Is this prompt free to use?
Yes. Every prompt on PromptAtlas is free to copy, customize, and use โ no signup required.
Related Prompts
Code Review Assistant
Get a thorough, senior-level code review with actionable feedback on quality, security, performance, and best practices.
Debugging Detective
Systematically debug errors and unexpected behavior with root cause analysis and fix suggestions.
Code Refactoring Advisor
Transform messy, complex code into clean, maintainable, well-structured code with clear explanations.