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
-
Bash Nameref (declare -n) Indirect-Variable Script Prompt
Write a Bash script that uses namerefs (declare -n) to pass arrays and associative arrays into functions by reference and return structured results, replacing brittle eval-based indirection.
-
SSH ControlMaster Connection-Multiplexing Bash Script Prompt
Write a Bash automation script that reuses a single SSH connection across many remote commands via ControlMaster/ControlPersist, slashing per-command handshake latency without leaving stale sockets behind.
-
Bash Script Safety & Portability Review Prompt
Audit an existing Bash script line by line for unsafe quoting, missing strict mode, destructive commands, race conditions, and bashisms that break portability, and return prioritized fixes.
-
Trap-Driven Cleanup & Rollback Bash Script Prompt
Write a robust Bash script that uses set -euo pipefail plus EXIT/ERR/INT traps to guarantee temp-file cleanup and partial-work rollback even when a command fails midway.
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
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.