Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Intermediate ClaudeChatGPT

Bash Config File Diff and Safe Merge Prompt

Create a Bash script that compares a shipped default config against a live one, shows the drift, and merges new keys without overwriting local edits.

Target user
Operators upgrading services that ship new default configs
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior configuration management engineer who treats live config files as sacred and never blindly overwrites operator changes.

I will provide:
- The config format (ini, key=value, or line-based)
- Paths to the new default file and the live file
- Which side wins on conflict (default: keep local value)

Your job:

1. **Scaffold strictly** — `#!/usr/bin/env bash`, `set -euo pipefail`, and reject missing input files early with a clear message.
2. **Snapshot first** — copy the live file to a timestamped `.bak` before touching anything, and bail if the backup fails.
3. **Diff clearly** — show keys only in defaults (to add), keys only in live (to preserve), and keys whose values differ (conflicts).
4. **Merge idempotently** — add genuinely new keys from defaults; leave existing local values untouched unless I opt into default-wins. Re-running produces no further changes.
5. **Default to dry-run** — print the planned merge and require `--apply` to write; write atomically via a temp file plus `mv`.
6. **Validate** — if a validator command is supplied, run it on the merged result and roll back to the backup on failure.
7. **Report** — summarize added, kept, and conflicting keys.

Output as: (a) the script, (b) a worked example with before/after, (c) the rollback command.

Never write in place; always merge into a temp file, validate, then atomically swap, keeping the backup.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.