shell-portability

Write portable shell scripts compatible across systems, shells, and environments.

1|Updated Jun 18, 2025
One-click install
npx skills add https://github.com/knopki/dotfiles --skill shell-portability-knopki
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: shell-portability
Source: https://github.com/knopki/dotfiles/tree/main/home/private_dot_config/opencode/skills/shell-portability
Command: npx skills add https://github.com/knopki/dotfiles --skill shell-portability-knopki

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you write shell scripts that function reliably across diverse operating systems, shells, and environments, avoiding common compatibility pitfalls.

Core Features & Use Cases

  • Cross-Platform Compatibility: Provides guidance on writing scripts that work on Linux, macOS, and BSD.
  • Shell Feature Differences: Details differences between Bash and POSIX shells for arrays, test syntax, string operations, and arithmetic.
  • Platform-Specific Command Handling: Offers portable solutions for commands like date, sed, and readlink that behave differently across systems.
  • Environment Detection: Includes functions to detect the operating system, architecture, and shell type.
  • Use Case: Ensure your deployment scripts run seamlessly whether they are executed on a developer's macOS machine or a production Linux server.

Quick Start

Use the shell-portability skill to write a bash script that detects the operating system it is running on.

Frequently Asked Questions about shell-portability

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

FAQPage Schema
How do I write cross-platform shell scripts that work on both Linux and macOS?

Writing cross-platform shell scripts requires addressing POSIX compatibility, detecting the operating system, and accounting for platform-specific command variations for utilities like date, sed, and readlink to ensure reliable execution across Linux, macOS, and BSD.

What is the difference between Bash and POSIX shell syntax for arrays and string operations?

Bash and POSIX shells differ significantly in arrays, test syntax, string operations, and arithmetic. POSIX compliance restricts arrays and alters test syntax, requiring specific portable patterns to avoid compatibility pitfalls when writing shell scripts.

How do I detect the operating system and architecture in a shell script?

Detecting the operating system and architecture in a shell script involves using environment detection functions to identify the current platform and shell type. This allows scripts to conditionally execute platform-specific commands for cross-platform compatibility.

What is the best way to handle portable temporary files and file reading in shell scripting?

Portable temporary file creation and file reading rely on POSIX-compliant patterns rather than shell-specific extensions. These portable patterns ensure scripts function predictably across different systems, shells, and environments without relying on Bash-only features.

Why does my shell script fail when checking command existence across different systems?

Shell scripts fail across different systems due to non-portable command existence checks. Using portable patterns for checking command availability ensures the script correctly identifies platform-specific command variations and avoids execution errors.

When do I need to worry about POSIX compatibility in my bash scripts?

You need to worry about POSIX compatibility in bash scripts when deploying across diverse operating systems, shells, and environments. Ensuring POSIX compliance prevents common compatibility pitfalls related to arrays, test syntax, and platform-specific commands.