shell-expert

Provides shell scripting reference covering Bash, Zsh, and POSIX sh compatibility, pitfalls, and idioms.

Updated Jun 24, 2026
One-click install
npx skills add https://github.com/psmfd/pi-config --skill shell-expert-psmfd
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: shell-expert
Source: https://github.com/psmfd/pi-config/tree/main/agent/skills/shell-expert
Command: npx skills add https://github.com/psmfd/pi-config --skill shell-expert-psmfd

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing portable, correct shell scripts is hard: Bash, Zsh, and POSIX sh differ in feature support, GNU and BSD coreutils behave differently, and subtle pitfalls like word splitting, subshell variable scope, and set -e edge cases cause silent bugs. This Skill gives an AI agent a read-only reference of compatibility matrices, idioms, and security patterns so shell guidance is accurate on the first attempt. ## Core Features & Use Cases - Compatibility Matrices: Feature availability tables for POSIX sh vs Bash vs Zsh, plus GNU vs BSD coreutils differences (sed -i, grep -P, stat, date, mktemp) with portable alternatives. - Pitfall and Security Patterns: Documented fixes for word splitting, pipeline subshell scope, pipefail behavior, command injection, temp file races, credential handling, and signal-safe cleanup traps. - Idioms and Process Control: Parameter expansion reference, here-documents, array patterns, job control, lock files, shell startup file load order, and CLI exploration strategy. - Use Case: When asked to write a cross-platform install script, the agent consults this reference to choose a portable shebang, avoid GNU-only flags, quote expansions correctly, and add trap-based cleanup. ## Quick Start Ask the agent to write or review a shell script for a specific platform, for example to create a portable Bash backup script that works on both macOS and Debian.

Frequently Asked Questions about shell-expert

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

FAQPage Schema
How do I write a portable shell script for Bash and POSIX sh?▼

Target POSIX sh with #!/bin/sh when the script must run anywhere, and use #!/usr/bin/env bash only when Bash features like arrays or [[ ]] are required. The reference includes a feature availability matrix showing which constructs each shell supports.

What is the difference between GNU and BSD coreutils commands?▼

GNU tools on Linux and BSD tools on macOS differ in flags like sed -i, grep -P, stat, date, and readlink -f. The reference provides a comparison table with portable alternatives, such as using sed output redirection instead of sed -i.

Why does my variable lose its value inside a while read loop?▼

Pipes create subshells, so variables set inside a piped while loop are lost when it ends. Fix it with process substitution (while read ... done < <(command)), a here-string, or restructuring to avoid the pipe.

Does set -e catch all errors in a Bash script?▼

No. set -e does not trigger in if conditions, while/until conditions, && or || chains, or functions called from those contexts. Use set -euo pipefail as a baseline but check critical command exit codes explicitly.

How do I safely handle temporary files and secrets in shell scripts?▼

Use mktemp for unpredictable temp file names and register a trap to clean up on EXIT, INT, and TERM. Never embed credentials in scripts or pass them as command-line arguments; use environment variables or files with 600 permissions.

Where should I put PATH and aliases in Bash vs Zsh config files?▼

In Bash, put PATH in ~/.profile or ~/.bash_profile and interactive config in ~/.bashrc. In Zsh, ~/.zshenv runs for all invocations so keep it minimal, and put aliases and prompt setup in ~/.zshrc.