Shell scripting expertise covering POSIX-compliant and Bash-specific patterns, defensive scripting practices, cross-platform compatibility, and command-line automation. Use when working with .sh files, shell scripts, or when the user mentions Bash, POSIX, shell scripting, shebang, pipelines, or CLI automation. Also use for set -e, traps, parameter expansion, or cross-platform shell compatibility.
Expert guidance for writing robust, portable shell scripts.
For immediate help, identify your task type and consult the relevant reference:
| Working On | Reference File | Key Topics |
|---|---|---|
| Portable scripts, sh compatibility | posix-scripting | POSIX subset, portability |
| Arrays, advanced expansion | bash-features | Bash-specific extensions |
| Error handling, safety flags | defensive-patterns | set flags, traps, validation |
| macOS vs Linux differences |
| cross-platform |
| GNU vs BSD, path differences |
These principles apply across all shell scripting:
set -euo pipefail"$var" not $var[[ ]] for conditionals in Bash (more predictable than [ ])input_file not fset -e)set -u)set -o pipefail)#!/usr/bin/env bash
set -euo pipefail
# Description: What this script does
# Usage: script.sh <arg1> [arg2]
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly SCRIPT_NAME="$(basename "$0")"
cleanup() {
# Remove temp files, kill background processes
:
}
trap cleanup EXIT
die() {
echo "${SCRIPT_NAME}: error: $*" >&2
exit 1
}
usage() {
echo "Usage: ${SCRIPT_NAME} <arg1> [arg2]"
exit 1
}
main() {
[[ $# -lt 1 ]] && usage
local arg1="$1"
# Implementation here
}
main "$@"
$var instead of "$var"set -e or explicit checksls output instead of using globs or find -print0eval with untrusted input#!/bin/sh scripts/usr/local/bin vs /usr/bin)echo behavior (use printf for portability)For programmatic access: posix-scripting · bash-features · defensive-patterns · cross-platform