shell-portability

Solve cross-platform portability issues for shell scripts across Bash and POSIX sh environments.

187|20|Updated Nov 20, 2025
One-click install
npx skills add https://github.com/TheBushidoCollective/han --skill shell-portability
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: shell-portability
Source: https://github.com/TheBushidoCollective/han/tree/main/jutsu/jutsu-shellcheck/skills/shell-portability
Command: npx skills add https://github.com/TheBushidoCollective/han --skill shell-portability

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you craft shell scripts that run reliably on different operating systems and shells, minimizing environment-specific bugs and maintenance.

Core Features & Use Cases

  • POSIX Compatibility: Write scripts that work on POSIX-compliant shells.
  • Shell Dialect Awareness: Handle Bash vs. pure sh differences gracefully.
  • Cross-Platform Diligence: Provide portable workarounds for common platform quirks.

Quick Start

Create a portable script that prints the current date on Linux and macOS without relying on non-POSIX features.

Frequently Asked Questions about shell-portability

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write shell scripts that work across Linux, macOS, and BSD?

Write shell scripts using POSIX-compliant syntax and features supported by both bash and sh. Avoid bash-specific extensions, use portable command alternatives across platforms, detect the environment at runtime, and test on target systems to ensure cross-platform compatibility.

What's the difference between bash and POSIX sh, and how do I handle both?

POSIX sh is a minimal standard shell; bash extends it with additional features. Handle both by writing to POSIX standards, using feature detection, providing fallback implementations for bash-only features, and selecting appropriate shebangs for your script's requirements.

How do I make my shell scripts portable across different operating systems?

Ensure portability by using POSIX-compliant commands, avoiding platform-specific tools, handling command variations with conditional logic, detecting the OS and shell at runtime, following ShellCheck guidance, and providing documented workarounds for known platform quirks.

What shebang should I use for a portable shell script?

Use `#!/bin/sh` for maximum POSIX compatibility across systems, or `#!/usr/bin/env sh` for environments where sh may not be in /bin. Avoid bash-specific shebangs unless your script requires bash features unavailable in POSIX sh.

Why do my shell scripts fail when I move them between systems?

Scripts fail across systems due to non-POSIX features, platform-specific command variations, shell dialect differences, and missing environment setup. Diagnose with ShellCheck, verify POSIX compliance, test command availability on target platforms, and implement portable fallbacks.

Can I run the same shell script on Windows, Linux, and macOS without modification?

Yes, by writing strictly portable scripts using POSIX syntax, avoiding platform-specific commands, handling path separators and line endings correctly, and detecting the runtime environment. Test on all target platforms and provide fallback implementations for OS-specific operations.