posix-shell-pro
Write portable POSIX shell scripts for any Unix system
Shell scripts often fail on different systems due to bash-specific features. This skill ensures your scripts run everywhere using strict POSIX compliance.
下載技能 ZIP
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
開啟並開始使用
測試它
正在使用「posix-shell-pro」。 Create a POSIX script that backs up a directory with validation
預期結果:
- #!/bin/sh
- set -eu
- Usage: backup.sh <source_dir> <dest_dir>
- if [ $# -lt 2 ]; then
- echo "Error: source and destination required" >&2
- exit 1
- fi
- src="$1"
- dest="$2"
- [ -d "$src" ] || { echo "Source not a directory" >&2; exit 1; }
- mkdir -p "$dest" || exit 1
- tar -cf - -C "$src" . | (cd "$dest" && tar -xf -)
- echo "Backup completed successfully"
正在使用「posix-shell-pro」。 Check if a command exists portably
預期結果:
Use: command -v cmd >/dev/null 2>&1 && echo "found" || echo "missing"
安全審計
安全This is a prompt-only skill with no executable code. Static analysis scanned 0 files and detected 0 security issues with a risk score of 0/100. The skill provides instructional content on POSIX shell scripting best practices and actually promotes security patterns including input validation, safe variable quoting, cleanup traps, and warnings against eval on untrusted input. No network calls, command execution, or sensitive operations detected.
風險因素
⚙️ 外部命令
品質評分
你能建構什麼
Cross-platform deployment scripts
Create installation and deployment scripts that work identically on Linux, BSD, macOS, and embedded systems without requiring bash installation.
Container and embedded system tooling
Build lightweight scripts for Alpine Linux, BusyBox, and resource-constrained environments where bash is unavailable.
Legacy system administration
Maintain and modernize scripts for older Unix systems like Solaris, AIX, and legacy Linux that may lack bash or use older versions.
試試這些提示
Create a POSIX-compliant shell script that validates input arguments and performs a simple file operation. Include proper error handling with set -eu, input validation, and cleanup traps.
Convert this bash script to strict POSIX sh. Replace all arrays, [[ conditionals, and bash-specific features with POSIX-compliant equivalents. Explain each change made.
Implement POSIX-compliant argument parsing for a script that accepts -h for help, -v for verbose, -o for output file, and positional arguments. Use while and case without getopts for long options.
Create a POSIX shell function library that handles platform differences between Linux, BSD, macOS, and BusyBox. Include OS detection, command availability checks, and portable implementations of common utilities.
最佳實務
- Always quote variable expansions as "$var" to prevent word splitting and globbing
- Use printf instead of echo for all output since echo behavior varies across shells
- Implement cleanup with trap commands to remove temporary files on EXIT INT and TERM signals
避免
- Using [[ conditionals or bash arrays which fail on dash ash and other POSIX shells
- Using echo -e or echo -n which have inconsistent behavior across different systems
- Using process substitution <() or source command instead of pipes and dot operator