posix-shell-pro – skill Khác cho agent AI
Chuyên gia viết script POSIX sh nghiêm ngặt để đạt tính di động tối đa trên các hệ Unix-like. Chuyên viết shell script chạy được trên mọi shell tuân thủ POSIX (dash, ash, sh, bash --posix).
Cài skill posix-shell-pro bằng một lệnh
Chọn công cụ bạn đang dùng, copy lệnh và dán vào terminal. Skill sẽ nằm trong thư mục skills của công cụ đó và sẵn sàng dùng ở phiên làm việc tiếp theo.
Claude Code
mkdir -p ~/.claude/skills && curl -fsSL https://skill.dn1nguoi.com/z/posix-shell-pro-0fb18.tgz | tar xz -C ~/.claude/skills
Gọi trong Claude Code: /posix-shell-pro – rồi mô tả công việc bạn muốn làm.
Codex
mkdir -p ~/.codex/skills && curl -fsSL https://skill.dn1nguoi.com/z/posix-shell-pro-0fb18.tgz | tar xz -C ~/.codex/skills
Gọi trong Codex: $posix-shell-pro – rồi mô tả công việc bạn muốn làm.
Hermes Agent
mkdir -p ~/.hermes/skills && curl -fsSL https://skill.dn1nguoi.com/z/posix-shell-pro-0fb18.tgz | tar xz -C ~/.hermes/skills
Gọi trong Hermes Agent: /posix-shell-pro – rồi mô tả công việc bạn muốn làm.
DeepSeek
mkdir -p ~/.deepcode/skills && curl -fsSL https://skill.dn1nguoi.com/z/posix-shell-pro-0fb18.tgz | tar xz -C ~/.deepcode/skills
Gọi trong DeepSeek: /posix-shell-pro – rồi mô tả công việc bạn muốn làm.
Nội dung SKILL.md
Nội dung SKILL.md gốc bằng tiếng Anh.
Use this skill when
- Working on posix shell pro tasks or workflows
- Needing guidance, best practices, or checklists for posix shell pro
Do not use this skill when
- The task is unrelated to posix shell pro
- You need a different domain or tool outside this scope
Instructions
- Clarify goals, constraints, and required inputs.
- Apply relevant best practices and validate outcomes.
- Provide actionable steps and verification.
Focus Areas
- Strict POSIX compliance for maximum portability
- Shell-agnostic scripting that works on any Unix-like system
- Defensive programming with portable error handling
- Safe argument parsing without bash-specific features
- Portable file operations and resource management
- Cross-platform compatibility (Linux, BSD, Solaris, AIX, macOS)
- Testing with dash, ash, and POSIX mode validation
- Static analysis with ShellCheck in POSIX mode
- Minimalist approach using only POSIX-specified features
- Compatibility with legacy systems and embedded environments
Portability target: widely deployed POSIX.1-2017 shells unless the user explicitly selects POSIX.1-2024. Newer-standard features may be absent on legacy systems. Shell conformance and utility availability are separate; test both on target hosts.
POSIX Constraints
- No arrays (use positional parameters or delimited strings)
- No
[[conditionals (use[test command only) - No process substitution
<()or>() - No brace expansion
{1..10} - No
localkeyword (use function-scoped variables carefully) - No
declareortypeset; POSIXreadonly name=valueis supported - No
+=operator for string concatenation - No
${var//pattern/replacement}substitution - No associative arrays or hash tables
- No
sourcecommand (use.for sourcing files)
Approach
- Always use
#!/bin/shshebang for POSIX shell - Consider
set -eu, while checking expected failures explicitly;-ehas conditional/subshell exceptions.pipefailis standardized in POSIX.1-2024 but unavailable on many 2017-era shells - Quote all variable expansions:
"$var"never$var - Use
[ ]for all conditional tests, never[[ - Implement argument parsing with
whileandcase(nogetoptsfor long options) - Use
mktemponly after checking it exists (not a POSIX.1-2017 utility); otherwise require a reviewed platform-specific secure temporary-directory strategy - Use
printfinstead ofechofor all output (echo behavior varies) - Use
. script.shinstead ofsource script.shfor sourcing - Implement error handling with explicit
|| exit 1checks - Design scripts to be idempotent and support dry-run modes
- Use
IFSmanipulation carefully and restore original value - Validate inputs with
[ -n "$var" ]and[ -z "$var" ]tests - End option parsing with
--and userm -rf -- "$dir"for safety - Use command substitution
$()instead of backticks for readability - Implement structured logging with timestamps using
date - Test scripts with dash/ash to verify POSIX compliance
Compatibility & Portability
- Use
#!/bin/shto invoke the system's POSIX shell - Test on multiple shells: dash (Debian/Ubuntu default), ash (Alpine/BusyBox), bash --posix
- Avoid GNU-specific options; use POSIX-specified flags only
- Handle platform differences:
uname -sfor OS detection - Use
command -vinstead ofwhich(more portable) - Check for command availability:
command -v cmd >/dev/null 2>&1 || exit 1 - Provide portable implementations for missing utilities
- Use
[ -e "$file" ]for existence checks (works on all systems) - Avoid
/dev/stdin,/dev/stdout(not universally available) - Use explicit redirection instead of
&>(bash-specific)
Readability & Maintainability
- Use descriptive variable names in UPPER_CASE for exports, lower_case for locals
- Add section headers with comment blocks for organization
- Keep functions under 50 lines; extract complex logic
- Use consistent indentation (spaces only, typically 2 or 4)
- Document function purpose and parameters in comments
- Use meaningful names:
validate_inputnotcheck - Add comments for non-obvious POSIX workarounds
- Group related functions with descriptive headers
- Extract repeated code into functions
- Use blank lines to separate logical sections
Safety & Security Patterns
- Quote all variable expansions to prevent word splitting
- Validate file permissions before operations:
[ -r "$file" ] || exit 1 - Sanitize user input before using in commands
- Validate numeric input:
case $num in ''|*[!0-9]*) exit 1 ;; esac - Never use
evalon untrusted input - Use
--to separate options from arguments:rm -- "$file" - Validate required variables:
[ -n "$VAR" ] || { echo "VAR required" >&2; exit 1; } - Check exit codes explicitly:
cmd || { echo "failed" >&2; exit 1; } - Use
trapfor cleanup:trap 'rm -f "$tmpfile"' 0; trap 'exit 1' HUP INT TERM - Set restrictive umask for sensitive files:
umask 077 - Log security-relevant operations to syslog or file
- Validate file paths don't contain unexpected characters
- Use full paths for commands in security-critical scripts:
/bin/rmnotrm
Performance Optimization
- Use shell built-ins over external commands when possible
- Avoid spawning subshells in loops: use
while readnotfor i in $(cat) - Cache command results in variables instead of repeated execution
- Use
casefor multiple string comparisons (faster than repeatedif) - Process files line-by-line for large files
- Use
expror$(( ))for arithmetic (POSIX supports$(( ))) - Minimize external command calls in tight loops
- Use
grep -qwhen you only need true/false (faster than capturing output) - Batch similar operations together
- Use here-documents for multi-line strings instead of multiple echo calls
Documentation Standards
- Implement
-hflag for help (avoid--helpwithout proper parsing) - Include usage message showing synopsis and options
- Document required vs optional arguments clearly
- List exit codes: 0=success, 1=error, specific codes for specific failures
- Document prerequisites and required commands
- Add header comment with script purpose and author
- Include examples of common usage patterns
- Document environment variables used by script
- Provide troubleshooting guidance for common issues
- Note POSIX compliance in documentation
Working Without Arrays
Since POSIX sh lacks arrays, use these patterns:
- Positional Parameters:
set -- item1 item2 item3; for arg; do echo "$arg"; done - Delimited Strings: Prefer positional parameters. If splitting is intentional, disable pathname expansion, preserve/restore the original IFS (including unset state), and define empty-field behavior; do not reset IFS blindly to one space
- Newline-Separated: use
while IFS= read -r item || [ -n "$item" ]; do printf '%s\n' "$item"; done < "$input_file"; quoted"a\nb"contains literal backslashes, not newlines - Counters:
i=0; while [ $i -lt 10 ]; do i=$((i+1)); done - Field Splitting: Use
cut,awk, or parameter expansion for string splitting
Portable Conditionals
Use [ ] test command with POSIX operators:
- File Tests:
[ -e file ]exists,[ -f file ]regular file,[ -d dir ]directory - String Tests:
[ -z "$str" ]empty,[ -n "$str" ]not empty,[ "$a" = "$b" ]equal - Numeric Tests:
[ "$a" -eq "$b" ]equal,[ "$a" -lt "$b" ]less than - Logical:
[ cond1 ] && [ cond2 ]AND,[ cond1 ] || [ cond2 ]OR - Negation:
[ ! -f file ]not a file - Pattern Matching: Use
casenot[[ =~ ]]
CI/CD Integration
- Matrix testing: Test across dash, ash, bash --posix, yash on Linux, macOS, Alpine
- Container testing: Pin reviewed Alpine/Debian image digests for reproducible ash/dash tests; floating tags move
- Pre-commit hooks: Configure checkbashisms, shellcheck -s sh, shfmt -ln posix
- GitHub Actions: Use shellcheck-problem-matchers with POSIX mode
- Cross-platform validation: Test on Linux, macOS, FreeBSD, NetBSD
- BusyBox testing: Validate on BusyBox environments for embedded systems
- Automated releases: Tag versions and generate portable distribution packages
- Coverage tracking: Ensure test coverage across all POSIX shells
- Example workflow:
shellcheck -s sh *.sh && shfmt -ln posix -d *.sh && checkbashisms *.sh
Embedded Systems & Limited Environments
- BusyBox compatibility: Test with BusyBox's limited ash implementation
- Alpine Linux: Default shell is BusyBox ash, not bash
- Resource constraints: Minimize memory usage, avoid spawning excessive processes
- Missing utilities: Provide fallbacks when common tools unavailable (
mktemp,seq) - Read-only filesystems: Handle scenarios where
/tmpmay be restricted - No coreutils: Some environments lack GNU coreutils extensions
- Signal handling: Limited signal support in minimal environments
- Startup scripts: Init scripts must b
… (nội dung đầy đủ có trong gói tải về)
Skill liên quan
- powershell-windows – Mẫu PowerShell trên Windows. Các lỗi thường gặp nghiêm trọng, cú pháp toán tử, xử lý lỗi.
- pr-merge-champion – Tối ưu pull request để được duyệt và merge nhanh, bằng cách đảm bảo diff sạch, tự rà…
- product-description-generator – Trình tạo mô tả sản phẩm. Dùng khi làm việc với tính năng sản phẩm đã được xác minh và…
- product-manager – Hướng dẫn chiến lược sản phẩm, khám phá, ưu tiên và chỉ số; các mẫu thượng nguồn và bộ…
- product-manager-toolkit – Công cụ và khung làm việc thiết yếu cho quản lý sản phẩm hiện đại, từ khám phá đến triển…
- product-photo-studio – Cài đặt và sử dụng gói AI Product Photography chính thức, được ghim theo digest, cho…
- production-scheduling – Kiến thức chuyên môn được hệ thống hóa về lập lịch sản xuất, sắp xếp thứ tự công việc…
- progressive-web-app – Xây dựng Progressive Web App (PWA) với hỗ trợ offline, khả năng cài đặt và chiến lược…