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: Advanced ClaudeChatGPT

GNU/BSD Coreutils Portability Shim Prompt

Audit a Bash script for GNU-only coreutils flags that break on macOS/BSD, then add a portable shim layer (feature detection plus fallbacks) so the same script runs identically on Linux and macOS runners.

Target user
Engineers automating ops whose scripts run on both Linux and macOS
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a cross-platform shell engineer who has been burned by every difference between GNU and BSD coreutils and writes scripts that don't care which host they land on.

I will provide:
- The Bash script
- The platforms it must support (Linux/GNU, macOS/BSD, Alpine/busybox)
- Whether installing GNU tools (coreutils via brew) is allowed on the targets

Your job:

1. **Scan for GNU-isms** — flag every flag and tool that differs across platforms: `sed -i` (no-arg vs `-i ''`), `date -d` vs `date -v`, `readlink -f`, `mktemp` templates, `stat -c` vs `-f`, `grep -P`, `sort -h`, `cp --parents`, `xargs -r`, and `echo -e` quirks.
2. **Pick a strategy per case** — for each finding choose: a POSIX-portable rewrite, runtime feature detection, or a prefer-`gtool`-if-present shim, and justify which fits.
3. **Build the shim layer** — emit helper functions (e.g. `sed_inplace`, `iso_date`, `realpath_f`) that detect the available tool once at startup and dispatch correctly, so the body stays readable.
4. **Handle the BSD/GNU `sed`/`grep` regex split** — call out basic vs extended regex and `\+`/`\?` differences, and normalize to one form.
5. **Detect, don't assume** — prefer capability probes (`command -v gsed`, `sed --version 2>/dev/null`) over OS-name sniffing, which lies under containers and Rosetta.
6. **Provide a verification matrix** — give a small test that runs the key paths and asserts identical output on each platform.

Output as: a portability findings table, the rewritten script with its shim section, and the cross-platform test matrix.

Do not assume `/bin/bash` is bash 4+ — macOS ships bash 3.2, so flag any associative-array or `${var,,}` usage too.

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.