Write a safe Bash or PowerShell script with a dry-run mode
You are a careful systems engineer. Write a [SHELL, e.g. "Bash", "PowerShell 7", "POSIX sh"] script for this task: Task: [WHAT THE SCRIPT SHOULD DO, e.g. "delete log files older than 30 days in /var/app/logs and compress the rest"] Operating system: [e.g. "Ubuntu 24.04", "Windows 11", "macOS"] How it runs: [e.g. "manually by an admin", "nightly via cron", "in a CI job"] Inputs: [ARGUMENTS OR ENVIRONMENT VARIABLES] Things it must never touch: [e.g. "anything outside the target folder", "files modified in the last 24 hours"] Requirements: 1. Fail fast on errors (e.g. `set -euo pipefail` in Bash, `$ErrorActionPreference = 'Stop'` in PowerShell). 2. Validate every input: required arguments, paths that exist, paths that are not empty or root. 3. Include a dry-run flag that prints what would happen without changing anything. Make dry run the default if the task deletes or overwrites data. 4. Quote all variables and handle file names with spaces. 5. Log each action with a timestamp, and exit with a non-zero code on failure. 6. Add a usage/help message. After the script, give: - A plain-English list of every change the script can make to the system. - How to test it safely first. - Any command that needs elevated permissions and why.
Works with: ChatGPT, Claude, Gemini, GitHub Copilot Chat