plugins/bash-development/skills/bash-portability/SKILL.md
This skill should be used when the user asks about "POSIX compatibility", "portable shell scripts", "cross-shell compatibility", "bashisms", "shebang selection", or mentions writing scripts that work on different shells (bash, sh, dash, zsh) or different systems.
npx skillsauth add jamie-bitflight/claude_skills bash-portabilityInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Guidance for writing portable POSIX-compatible scripts and understanding when to leverage bash-specific features.
#!/usr/bin/env bash for Bash Scripts#!/usr/bin/env bash
Why: Searches PATH for bash, works across systems where bash may be in different locations.
#!/bin/sh for POSIX Scripts#!/bin/sh
Why: Maximum portability when bash features aren't needed. On many systems, /bin/sh is dash or another POSIX shell.
#!/bin/bash
Use only when: System requirements guarantee bash location, or security policy requires absolute paths.
| Feature | POSIX | Bash | Recommendation |
| -------------- | ------- | ---- | ------------------------------ | ---- |
| [[ ]] | No | Yes | Use [ ] for POSIX |
| (( )) | No | Yes | Use [ ] with -eq etc. |
| Arrays | No | Yes | Use positional params or files |
| local | Partial | Yes | Generally safe |
| ${var,,} | No | 4+ | Use tr for POSIX |
| <<< | No | Yes | Use echo | cmd |
| =~ regex | No | Yes | Use grep or expr |
| source | No | Yes | Use . (dot) command |
| function f() | No | Yes | Use f() only |
| $'...' | No | Yes | Use printf |
| {1..10} | No | Yes | Use seq or while loop |
# POSIX - use [ ] with proper quoting
if [ -f "$file" ]; then
echo "File exists"
fi
# String comparison
if [ "$var" = "value" ]; then
echo "Match"
fi
# Numeric comparison
if [ "$num" -gt 10 ]; then
echo "Greater"
fi
# Compound conditions
if [ -f "$file" ] && [ -r "$file" ]; then
echo "Readable file"
fi
# Lowercase
lower=$(echo "$string" | tr '[:upper:]' '[:lower:]')
# Uppercase
upper=$(echo "$string" | tr '[:lower:]' '[:upper:]')
# Get substring - use expr or cut
substr=$(expr "$string" : '.\{3\}\(.\{5\}\)') # chars 4-8
substr=$(echo "$string" | cut -c4-8)
# String length
length=$(expr length "$string")
length=${#string} # This is actually POSIX
# Line by line
while IFS= read -r line; do
echo "$line"
done < "$file"
# Read entire file (without cat)
content=$(cat "$file") # cat is POSIX
# Modern syntax (preferred even in POSIX)
result=$(command)
# Legacy syntax (avoid)
result=`command`
# Nested (why modern is better)
result=$(echo $(date)) # Clear
result=`echo \`date\`` # Escape nightmare
When portability isn't required, these bash features improve code quality:
[[ ]]# Pattern matching
[[ "$file" == *.txt ]]
# Regex matching
[[ "$input" =~ ^[0-9]+$ ]]
# No word splitting worries
[[ -f $file ]] # Quotes optional (but still recommended)
# Logical operators inside
[[ -f "$file" && -r "$file" ]]
# Indexed arrays
declare -a files=()
files+=("one.txt")
files+=("two.txt")
for f in "${files[@]}"; do
process "$f"
done
# Associative arrays (Bash 4+)
declare -A config
config[host]="localhost"
config[port]="8080"
# Default value
"${var:-default}"
# Case conversion (Bash 4+)
"${var,,}" # lowercase
"${var^^}" # uppercase
# Substring
"${var:0:10}" # first 10 chars
"${var: -5}" # last 5 chars
# Search/replace
"${var//old/new}"
# Bash
read -r var <<< "input string"
# POSIX equivalent
var=$(echo "input string")
# Bash - compare two command outputs
diff <(sort file1) <(sort file2)
# POSIX equivalent (with temp files)
sort file1 > /tmp/sorted1
sort file2 > /tmp/sorted2
diff /tmp/sorted1 /tmp/sorted2
# Check if running in bash
if [ -n "${BASH_VERSION:-}" ]; then
echo "Running in Bash"
fi
# Check bash version for features
if [ "${BASH_VERSINFO[0]:-0}" -ge 4 ]; then
echo "Bash 4+ available"
fi
# Generic shell detection
case "${SHELL##*/}" in
bash) echo "bash" ;;
zsh) echo "zsh" ;;
*) echo "other" ;;
esac
Code examples
Use POSIX when:
Use Bash when:
# Problematic - behavior varies
echo -n "no newline"
echo -e "with\ttabs"
# Portable
printf '%s' "no newline"
printf 'with\ttabs\n'
# Works everywhere
var="value"
# May fail on some shells
var = "value" # Spaces around = are wrong
# POSIX - separate commands
var="value"
export var
# Bash/modern - combined (works most places)
export var="value"
# Use positional parameters
set -- "item1" "item2" "item3"
for item in "$@"; do
echo "$item"
done
# Or IFS-based splitting
items="item1:item2:item3"
IFS=':' read -r item1 item2 item3 <<EOF
$items
EOF
development
When an application needs to store config, data, cache, or state files. When designing where user-specific files should live. When code writes to ~/.appname or hardcoded home paths. When implementing cross-platform file storage with platformdirs.
testing
Enforce mandatory pre-action verification checkpoints to prevent pattern-matching from overriding explicit reasoning. Use this skill when about to execute implementation actions (Bash, Write, Edit) to verify hypothesis-action alignment. Blocks execution when hypothesis unverified or action targets different system than hypothesis identified. Critical for preventing cognitive dissonance where correct diagnosis leads to wrong implementation.
tools
Reference guide for the Twelve-Factor App methodology — 15 principles (12 original + 3 modern extensions) for building portable, resilient, cloud-native applications. Use when evaluating application architecture, designing cloud-native services, reviewing codebases for methodology compliance, advising on configuration, scaling, observability, security, and deployment patterns. Incorporates the 2025 open-source community evolution and cloud-native reinterpretations of each factor.
tools
Converts user-facing documentation (how-to guides, tutorials, API references, examples) in any format — Markdown, PDF, DOCX, PPTX, XLSX, AsciiDoc, RST, HTML, Jupyter notebooks, man pages, TOML/YAML/JSON configs, and plain text — into Claude Code skill directories with SKILL.md plus thematically grouped references/*.md files. Use when given a docs directory or mixed-format documentation to transform into an AI skill. Uses MCP file-reader server for binary formats.