cross-platform-shell

Detect the operating system and normalize paths across Windows, WSL, Linux, and macOS shell scripts.

Updated Apr 11, 2023
One-click install
npx skills add https://github.com/salverius-tech/dotfiles --skill cross-platform-shell
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: cross-platform-shell
Source: https://github.com/salverius-tech/dotfiles/tree/main/home/dot_claude/skills/cross-platform-shell
Command: npx skills add https://github.com/salverius-tech/dotfiles --skill cross-platform-shell

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill provides robust shell scripting patterns that ensure your scripts run flawlessly across Windows (Git Bash/MSYS2), WSL, and native Linux/macOS environments, eliminating cross-platform compatibility headaches.

Core Features & Use Cases

  • Platform Detection: Accurately identify the operating system (Windows, WSL, Linux, macOS) within your scripts.
  • Path Normalization: Handle variations in Windows and WSL path formats to ensure consistency.
  • Symlink vs. Junction Handling: Create cross-platform compatible links, using junctions on Windows where symlinks are restricted.
  • CRLF Prevention: Ensure shell scripts maintain correct line endings to avoid execution errors.
  • Use Case: You need to deploy a setup script that installs dependencies and configures the environment on both a developer's Windows machine and a production Linux server. This Skill ensures your script correctly detects each OS and uses the appropriate commands and path conventions.

Quick Start

Use the cross-platform-shell skill to detect the current operating system and print its name.

Frequently Asked Questions about cross-platform-shell

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

FAQPage Schema
How do I write a bash script that works on both Windows and macOS?

To write cross-platform shell scripts, you must implement platform detection and path normalization to handle OS-specific differences. This ensures your bash scripts execute correctly across Windows Git Bash, macOS, and Linux environments.

Why do my shell scripts fail when moving from Linux to WSL?

Shell scripts often fail in WSL due to path format variations and incorrect line endings. Normalizing WSL paths and preventing CRLF line endings ensures your scripts execute reliably across different operating system environments.

What is the best way to detect the operating system in a shell script?

The best way to detect operating systems in shell scripts is using dedicated platform detection functions. This allows your script to identify Windows, WSL, Linux, or macOS and execute the appropriate OS-specific commands.

How do I handle symlinks in a script when Windows restricts them?

To handle symlinks when Windows restricts them, your script should detect the OS and create directory junctions on Windows instead. This allows cross-platform compatible linking behavior without requiring elevated permissions.

Can I use this to run a setup script on a Windows machine and a Linux server?

Yes, you can use this to run a single setup script on both a Windows machine and a Linux server. It detects each OS during execution and uses the appropriate commands, path conventions, and line endings.

How do I prevent CRLF line ending issues in shell scripts?

To prevent CRLF line ending issues in shell scripts, implement CRLF prevention patterns that enforce correct line endings. This avoids execution errors when scripts are edited or transferred between Windows and Linux environments.