thinkhard.SI

Prompt repository Engineering & code

Write a shell script to automate a repetitive task

You run the same steps in a terminal every week, such as renaming files or backing up a folder, and want a script that is safe to run again.

Registry no.
ENG-025
Collection
Engineering & code
Laid out for
Any chat model
Score
10 out of 10
Blanks to fill
7
Added

Engineering & codeAny chat

The prompt

Score 10 of 10, Excellent

Use it when You run the same steps in a terminal every week, such as renaming files or backing up a folder, and want a script that is safe to run again.

  • {{user}}
  • {{how_often}}
  • {{steps}}
  • {{shell}}
  • {{tools}}
  • {{where_it_runs}}
  • {{example_input}}
Full prompt and why it works
Prompt
Write a shell script that automates the task below for {{user}}, who will run it {{how_often}}, so that it gets done the same way every time without anyone retyping commands.

The steps I do by hand today:
"""
{{steps}}
"""

Operating system and shell: {{shell}}
Tools available: {{tools}}
Where it runs: {{where_it_runs}}

Example input (file names or a folder listing):
"""
{{example_input}}
"""

The script must:
1. Stop at the first error: start with set -euo pipefail in bash or zsh, or the equivalent for this shell.
2. Take paths and options as arguments or as variables at the top, never buried in the middle, and print a usage line when a required one is missing.
3. Offer a dry-run option that prints each action without doing it.
4. Quote every variable, so names with spaces work.
5. Be safe to run twice: a second run must not duplicate, overwrite or delete what the first run did.
6. Check that a target is what it should be before deleting or overwriting it, and never run rm -rf on a path built from a variable that could be empty.
7. Print one short line per step and a summary at the end, and exit with a non-zero status on failure.

Return the script in one code block with a comment above each section, then the exact commands to make it executable, run a dry run and run it for real, then up to 5 assumptions you made.

A good script is one I can read in two minutes and trust to run unattended. For example, the form of one log line: "Copied 42 files to /backups/<date> (skipped 3 already present)."

Use only commands available on {{shell}} plus the tools listed. The macOS and Linux versions of sed, date and find take different options, so write for the system named and say which one you wrote for. Do not use sudo unless a step needs it, and explain why if it does. If a step is ambiguous, such as what to do when a file already exists, write the safest choice, mark it with a # CHECK comment and list it with your assumptions.

Variables

{{user}}
Who will run it, for example "me" or "the office manager, who rarely uses a terminal".
{{how_often}}
For example "every Friday" or "each time a client sends files".
{{steps}}
The steps you do by hand today, in order, with the commands if you know them.
{{shell}}
For example "macOS with zsh" or "Ubuntu 24.04 with bash".
{{tools}}
Command-line tools you can use, such as rsync, jq or ImageMagick, or "only what comes with the system".
{{where_it_runs}}
For example "by hand on my laptop" or "nightly from cron on a server".
{{example_input}}
A few real file names or a folder listing, so the script handles the names you actually have.

Why it works

  • What to avoid. A dry-run mode, quoted variables and a ban on rm -rf with a possibly empty path cover the ways a small script most often destroys files.
  • What good looks like. Running the script twice must not repeat or undo work, which is what makes it safe to schedule, or to rerun after it fails halfway.
  • If unsure. Ambiguous steps get the safest choice and a # CHECK comment, so you can find every assumption in the script itself.

How to use it

  1. Press Fill in variables and type your details into each blank. What you type stays in this browser.
  2. Copy the filled prompt into the AI tool you already use, such as ChatGPT, Claude or Gemini, or open it in the Grader or the Prompt Tester here.
  3. Before you rely on it, try it on three or four real examples. The Prompt Tester runs them all at once and shows which ones go wrong.
Use it from code

Get this prompt as JSON from the free REST API, with your own text in the blanks, or let an AI assistant fetch it through the MCP server. No key.

curl -s https://thinkhard.si/api/v1/prompts/shell-script-for-repetitive-task

With the MCP server added to Claude, ChatGPT, Cursor or VS Code, call get_prompt with {"prompt": "shell-script-for-repetitive-task"}, or just ask for it by name.