Write a safe Bash script for any task

A ChatGPT prompt for Bash scripts — describe the task and get a commented script with safety flags, argument checks, logging and a dry-run mode.

Published
Works with
ChatGPT, Claude and Gemini
Level
Intermediate
By
GoodAIPromt editorial team

Shell scripts automate backups, file cleanups and deployments, but a small mistake — an unquoted variable, a missing check — can delete the wrong files. This ChatGPT prompt for Bash scripts turns your task description into a commented script with strict mode, input validation, logging and a dry-run option, so you can test it before it touches real data.

The prompt

Act as a senior Linux engineer. Write a Bash script.

Task, step by step: 
Inputs (arguments, files, environment variables): 
Expected output and where it goes: 
Operating system and shell version: [e.g. Ubuntu 24.04, bash 5 / macOS zsh]
How it will run (manually, cron, CI): 
Tools available (rsync, jq, curl…): 

Requirements:
1. Use set -euo pipefail, quote all variables, and use functions for each step.
2. Parse arguments with a --help message and a --dry-run flag that prints actions without changing anything.
3. Check that required tools, files and permissions exist before starting.
4. Log with timestamps to stdout and to a log file; exit with clear error codes.
5. Clean up temporary files with a trap.
6. Comment each section.
Then:
7. Show 3 example commands to run it.
8. Explain any destructive step and how to test it safely.
9. Note if Python or another tool would be a better fit.

0 of 5 blanks filled

How to use it

  1. Run with --dry-run first and read every planned action.
  2. Test in a temporary folder with copies of real files.
  3. Run ShellCheck on the script before scheduling it.

Tips

Frequently asked questions

What does this prompt do?

A ChatGPT prompt for Bash scripts — describe the task and get a commented script with safety flags, argument checks, logging and a dry-run mode.

Which AI tools does it work with?

It is written for ChatGPT, Claude and Gemini. It also works in other AI tools that accept text prompts, with small changes.

What do I need to fill in?

5 blanks: what the script should do; inputs; output; run context; tools. Click each blue blank on the page, type your details and press Copy prompt.

Is this prompt free to use?

Yes. You can copy and use it for personal and commercial work.

bash scriptshell scriptingautomationlinux

More prompts for ChatGPT, Claude, Gemini.