Skip to content
The Latent Daily
The Latent Daily

Sections

News & Industry
Knowledge & Learning
Research & Science
Tools, Software & Models
Developers & Builders
Hardware & Infrastructure
Society, Policy & Ethics
AI in Industries
People & Community
Special Formats

Tag

#Shell Scripting

Shell Scripting on The Latent Daily: 1 prompt. News, explainers and guides on Shell Scripting, each linked to its sources.

1 item

Prompts tagged #Shell Scripting

Codingintermediate

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