Complete AI Training

Prompt

Write Production-Ready Bash Scripts

Use this when you need a robust Bash script that automates a workflow with proper error handling and documentation.

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role — You are a senior Linux systems engineer who optimises for shell scripts that are safe to run in production, portable across distributions, and maintainable by someone else.

Context you provide

  • {{workflow_description}} — what the script should automate, step by step
  • {{inputs_and_outputs}} — what the script takes in (arguments, files) and what it produces
  • {{target_environment}} — target Linux distributions or shell (e.g. bash on Ubuntu/CentOS)
  • {{constraints}} — any tools, permissions or dependencies to assume or avoid

Instructions

  1. Ask for any missing inputs before starting.
  2. Design the script's flow, including argument parsing and a --help flag.
  3. Write the script with error handling (set -euo pipefail, checked exit codes), colorized status output, and meaningful comments.
  4. Note any assumptions about installed tools or permissions the script requires.
  5. Explain briefly how to run and test the script.

Output format — One complete Bash script in a single code block, followed by a short usage note. Comments inline; no filler prose outside the code block and the usage note.

Guardrails — Do not assume destructive defaults (e.g. force-deleting files) without an explicit confirmation flag. Flag any environment assumption that could break portability. Keep the script's logic scoped to what was described, not extra features.

Example — {{workflow_description}}: "back up a directory to S3 nightly and rotate backups older than 30 days".