Skilllibrary cross-platform-shell
install
source · Clone the upstream repo
git clone https://github.com/merceralex397-collab/skilllibrary
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/merceralex397-collab/skilllibrary "$T" && mkdir -p ~/.claude/skills && cp -r "$T/10-cli-systems-and-ops/cross-platform-shell" ~/.claude/skills/merceralex397-collab-skilllibrary-cross-platform-shell && rm -rf "$T"
manifest:
10-cli-systems-and-ops/cross-platform-shell/SKILL.mdsource content
Purpose
Write shell scripts and Makefile recipes that execute correctly on Linux, macOS, and Windows (Git Bash / WSL / MSYS2).
When to use this skill
- a shell script must run on both Linux and macOS (BSD vs GNU coreutils)
- writing Makefile recipes or CI scripts targeting multiple OS runners
- replacing
,sed -i
,grep -P
with portable alternativesreadlink -f - a project has contributors on macOS, Linux, and Windows
Do not use this skill when
- the script only targets Linux — prefer
bash - the task is Windows PowerShell automation — different domain
- building a compiled CLI tool — prefer
cli-development-go
Procedure
- Use POSIX sh when possible — start with
for max portability. Only use#!/bin/sh
if arrays or#!/usr/bin/env bash
are needed.[[ ]] - Avoid GNU extensions — use
notsed 's/a/b/'
(macOSsed -i 's/a/b/'
requiressed -i
). Use''
notgrep -E
.grep -P - Use portable path resolution — replace
withreadlink -f
.cd "$(dirname "$0")" && pwd -P - Handle line endings — ensure scripts use LF. Add
:.gitattributes
.*.sh text eol=lf - Abstract OS differences — detect OS with
and branch:uname -s
.case "$(uname -s)" in Darwin*) ... ;; Linux*) ... ;; MINGW*|MSYS*) ... ;; esac - Use
for interpreters —env
not#!/usr/bin/env python3
.#!/usr/bin/python3 - Test in CI on all targets — use GitHub Actions matrix with
,ubuntu-latest
,macos-latest
.windows-latest
Portability cheat sheet
| Task | GNU/Linux | macOS (BSD) | Portable |
|---|---|---|---|
| In-place edit | | | Write to temp, |
| Regex grep | | N/A | |
| Resolve symlink | | N/A | |
| Create temp file | | | |
| Date format | | | Use for epoch |
Decision rules
- If you need
, write to a temp file andsed -i
it back — works everywhere.mv - Prefer
overprintf
— echo behavior varies across shells.echo -e - Use
instead ofcommand -v
— POSIX compliant.which - Avoid associative arrays — they require Bash 4+ (macOS ships Bash 3).
- In Makefiles, set
only if Bash features are required.SHELL := /bin/bash
References
Related skills
— Linux-focused shell scriptingbash
— Linux-specific operationslinux-ubuntu-ops
— compiled cross-platform binary (avoids shell entirely)cli-development-go