[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M716TDW2NVCYBZ0GCEP52M2R":3,"skill-same:01M716TDW2NVCYBZ0GCEP52M2R":64},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":44,"commitSha":45,"skillDirectory":46,"forksCount":14,"repositoryHtmlUrl":47,"repositoryHomepageUrl":6,"ownerHtmlUrl":48,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":49,"install":50,"resources":63},"01M716TDW2NVCYBZ0GCEP52M2R","posix-shell-pro",null,"Expert in strict POSIX sh scripting for maximum portability across Unix-like systems. Specializes in shell scripts that run on any POSIX-compliant shell (dash, ash, sh, bash --posix).","sapsapshen\u002Fai-memory-router","sapsapshen","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F20347959?v=4","01M6XDQEF1DP50DKF37H81J3J5","shenmian","01M6XDQEJPE41Y3DT2763X8ZJN",0,"MIT","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fposix-shell-pro\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"shell","posix shell pro","posix","pro","unix","2026","dash","unknown","for","portability","scripts","systems","run","across","community","expert","Bash","shell scripts","scripting","2026-11-10 10:12:30",false,"---\nname: posix-shell-pro\ndescription: Expert in strict POSIX sh scripting for maximum portability across Unix-like systems. Specializes in shell scripts that run on any POSIX-compliant shell (dash, ash, sh, bash --posix).\nrisk: unknown\nsource: community\ndate_added: '2026-02-27'\n---\n\n## Use this skill when\n\n- Working on posix shell pro tasks or workflows\n- Needing guidance, best practices, or checklists for posix shell pro\n\n## Do not use this skill when\n\n- The task is unrelated to posix shell pro\n- You need a different domain or tool outside this scope\n\n## Instructions\n\n- Clarify goals, constraints, and required inputs.\n- Apply relevant best practices and validate outcomes.\n- Provide actionable steps and verification.\n- If detailed examples are required, open `resources\u002Fimplementation-playbook.md`.\n\n## Focus Areas\n\n- Strict POSIX compliance for maximum portability\n- Shell-agnostic scripting that works on any Unix-like system\n- Defensive programming with portable error handling\n- Safe argument parsing without bash-specific features\n- Portable file operations and resource management\n- Cross-platform compatibility (Linux, BSD, Solaris, AIX, macOS)\n- Testing with dash, ash, and POSIX mode validation\n- Static analysis with ShellCheck in POSIX mode\n- Minimalist approach using only POSIX-specified features\n- Compatibility with legacy systems and embedded environments\n\n## POSIX Constraints\n\n- No arrays (use positional parameters or delimited strings)\n- No `[[` conditionals (use `[` test command only)\n- No process substitution `\u003C()` or `>()`\n- No brace expansion `{1..10}`\n- No `local` keyword (use function-scoped variables carefully)\n- No `declare`, `typeset`, or `readonly` for variable attributes\n- No `+=` operator for string concatenation\n- No `${var\u002F\u002Fpattern\u002Freplacement}` substitution\n- No associative arrays or hash tables\n- No `source` command (use `.` for sourcing files)\n\n## Approach\n\n- Always use `#!\u002Fbin\u002Fsh` shebang for POSIX shell\n- Use `set -eu` for error handling (no `pipefail` in POSIX)\n- Quote all variable expansions: `\"$var\"` never `$var`\n- Use `[ ]` for all conditional tests, never `[[`\n- Implement argument parsing with `while` and `case` (no `getopts` for long options)\n- Create temporary files safely with `mktemp` and cleanup traps\n- Use `printf` instead of `echo` for all output (echo behavior varies)\n- Use `. script.sh` instead of `source script.sh` for sourcing\n- Implement error handling with explicit `|| exit 1` checks\n- Design scripts to be idempotent and support dry-run modes\n- Use `IFS` manipulation carefully and restore original value\n- Validate inputs with `[ -n \"$var\" ]` and `[ -z \"$var\" ]` tests\n- End option parsing with `--` and use `rm -rf -- \"$dir\"` for safety\n- Use command substitution `$()` instead of backticks for readability\n- Implement structured logging with timestamps using `date`\n- Test scripts with dash\u002Fash to verify POSIX compliance\n\n## Compatibility & Portability\n\n- Use `#!\u002Fbin\u002Fsh` to invoke the system's POSIX shell\n- Test on multiple shells: dash (Debian\u002FUbuntu default), ash (Alpine\u002FBusyBox), bash --posix\n- Avoid GNU-specific options; use POSIX-specified flags only\n- Handle platform differences: `uname -s` for OS detection\n- Use `command -v` instead of `which` (more portable)\n- Check for command availability: `command -v cmd >\u002Fdev\u002Fnull 2>&1 || exit 1`\n- Provide portable implementations for missing utilities\n- Use `[ -e \"$file\" ]` for existence checks (works on all systems)\n- Avoid `\u002Fdev\u002Fstdin`, `\u002Fdev\u002Fstdout` (not universally available)\n- Use explicit redirection instead of `&>` (bash-specific)\n\n## Readability & Maintainability\n\n- Use descriptive variable names in UPPER_CASE for exports, lower_case for locals\n- Add section headers with comment blocks for organization\n- Keep functions under 50 lines; extract complex logic\n- Use consistent indentation (spaces only, typically 2 or 4)\n- Document function purpose and parameters in comments\n- Use meaningful names: `validate_input` not `check`\n- Add comments for non-obvious POSIX workarounds\n- Group related functions with descriptive headers\n- Extract repeated code into functions\n- Use blank lines to separate logical sections\n\n## Safety & Security Patterns\n\n- Quote all variable expansions to prevent word splitting\n- Validate file permissions before operations: `[ -r \"$file\" ] || exit 1`\n- Sanitize user input before using in commands\n- Validate numeric input: `case $num in *[!0-9]*) exit 1 ;; esac`\n- Never use `eval` on untrusted input\n- Use `--` to separate options from arguments: `rm -- \"$file\"`\n- Validate required variables: `[ -n \"$VAR\" ] || { echo \"VAR required\" >&2; exit 1; }`\n- Check exit codes explicitly: `cmd || { echo \"failed\" >&2; exit 1; }`\n- Use `trap` for cleanup: `trap 'rm -f \"$tmpfile\"' EXIT INT TERM`\n- Set restrictive umask for sensitive files: `umask 077`\n- Log security-relevant operations to syslog or file\n- Validate file paths don't contain unexpected characters\n- Use full paths for commands in security-critical scripts: `\u002Fbin\u002Frm` not `rm`\n\n## Performance Optimization\n\n- Use shell built-ins over external commands when possible\n- Avoid spawning subshells in loops: use `while read` not `for i in $(cat)`\n- Cache command results in variables instead of repeated execution\n- Use `case` for multiple string comparisons (faster than repeated `if`)\n- Process files line-by-line for large files\n- Use `expr` or `$(( ))` for arithmetic (POSIX supports `$(( ))`)\n- Minimize external command calls in tight loops\n- Use `grep -q` when you only need true\u002Ffalse (faster than capturing output)\n- Batch similar operations together\n- Use here-documents for multi-line strings instead of multiple echo calls\n\n## Documentation Standards\n\n- Implement `-h` flag for help (avoid `--help` without proper parsing)\n- Include usage message showing synopsis and options\n- Document required vs optional arguments clearly\n- List exit codes: 0=success, 1=error, specific codes for specific failures\n- Document prerequisites and required commands\n- Add header comment with script purpose and author\n- Include examples of common usage patterns\n- Document environment variables used by script\n- Provide troubleshooting guidance for common issues\n- Note POSIX compliance in documentation\n\n## Working Without Arrays\n\nSince POSIX sh lacks arrays, use these patterns:\n\n- **Positional Parameters**: `set -- item1 item2 item3; for arg; do echo \"$arg\"; done`\n- **Delimited Strings**: `items=\"a:b:c\"; IFS=:; set -- $items; IFS=' '`\n- **Newline-Separated**: `items=\"a\\nb\\nc\"; while IFS= read -r item; do echo \"$item\"; done \u003C\u003CEOF`\n- **Counters**: `i=0; while [ $i -lt 10 ]; do i=$((i+1)); done`\n- **Field Splitting**: Use `cut`, `awk`, or parameter expansion for string splitting\n\n## Portable Conditionals\n\nUse `[ ]` test command with POSIX operators:\n\n- **File Tests**: `[ -e file ]` exists, `[ -f file ]` regular file, `[ -d dir ]` directory\n- **String Tests**: `[ -z \"$str\" ]` empty, `[ -n \"$str\" ]` not empty, `[ \"$a\" = \"$b\" ]` equal\n- **Numeric Tests**: `[ \"$a\" -eq \"$b\" ]` equal, `[ \"$a\" -lt \"$b\" ]` less than\n- **Logical**: `[ cond1 ] && [ cond2 ]` AND, `[ cond1 ] || [ cond2 ]` OR\n- **Negation**: `[ ! -f file ]` not a file\n- **Pattern Matching**: Use `case` not `[[ =~ ]]`\n\n## CI\u002FCD Integration\n\n- **Matrix testing**: Test across dash, ash, bash --posix, yash on Linux, macOS, Alpine\n- **Container testing**: Use alpine:latest (ash), debian:stable (dash) for reproducible tests\n- **Pre-commit hooks**: Configure checkbashisms, shellcheck -s sh, shfmt -ln posix\n- **GitHub Actions**: Use shellcheck-problem-matchers with POSIX mode\n- **Cross-platform validation**: Test on Linux, macOS, FreeBSD, NetBSD\n- **BusyBox testing**: Validate on BusyBox environments for embedded systems\n- **Automated releases**: Tag versions and generate portable distribution packages\n- **Coverage tracking**: Ensure test coverage across all POSIX shells\n- Example workflow: `shellcheck -s sh *.sh && shfmt -ln posix -d *.sh && checkbashisms *.sh`\n\n## Embedded Systems & Limited Environments\n\n- **BusyBox compatibility**: Test with BusyBox's limited ash implementation\n- **Alpine Linux**: Default shell is BusyBox ash, not bash\n- **Resource constraints**: Minimize memory usage, avoid spawning excessive processes\n- **Missing utilities**: Provide fallbacks when common tools unavailable (`mktemp`, `seq`)\n- **Read-only filesystems**: Handle scenarios where `\u002Ftmp` may be restricted\n- **No coreutils**: Some environments lack GNU coreutils extensions\n- **Signal handling**: Limited signal support in minimal environments\n- **Startup scripts**: Init scripts must be POSIX for maximum compatibility\n- Example: Check for mktemp: `command -v mktemp >\u002Fdev\u002Fnull 2>&1 || mktemp() { ... }`\n\n## Migration from Bash to POSIX sh\n\n- **Assessment**: Run `checkbashisms` to identify bash-specific constructs\n- **Array elimination**: Convert arrays to delimited strings or positional parameters\n- **Conditional updates**: Replace `[[` with `[` and adjust regex to `case` patterns\n- **Local variables**: Remove `local` keyword, use function prefixes instead\n- **Process substitution**: Replace `\u003C()` with temporary files or pipes\n- **Parameter expansion**: Use `sed`\u002F`awk` for complex string manipulation\n- **Testing strategy**: Incremental conversion with continuous validation\n- **Documentation**: Note any POSIX limitations or workarounds\n- **Gradual migration**: Convert one function at a time, test thoroughly\n- **Fallback support**: Maintain dual implementations during transition if needed\n\n## Quality Checklist\n\n- Scripts pass ShellCheck with `-s sh` flag (POSIX mode)\n- Code is formatted consistently with shfmt using `-ln posix`\n- Test on multiple shells: dash, ash, bash --posix, yash\n- All variable expansions are properly quoted\n- No bash-specific features used (arrays, `[[`, `local`, etc.)\n- Error handling covers all failure modes\n- Temporary resources cleaned up with EXIT trap\n- Scripts provide clear usage information\n- Input validation prevents injection attacks\n- Scripts portable across Unix-like systems (Linux, BSD, Solaris, macOS, Alpine)\n- BusyBox compatibility validated for embedded use cases\n- No GNU-specific extensions or flags used\n\n## Output\n\n- POSIX-compliant shell scripts maximizing portability\n- Test suites using shellspec or bats-core validating across dash, ash, yash\n- CI\u002FCD configurations for multi-shell matrix testing\n- Portable implementations of common patterns with fallbacks\n- Documentation on POSIX limitations and workarounds with examples\n- Migration guides for converting bash scripts to POSIX sh incrementally\n- Cross-platform compatibility matrices (Linux, BSD, macOS, Solaris, Alpine)\n- Performance benchmarks comparing different POSIX shells\n- Fallback implementations for missing utilities (mktemp, seq, timeout)\n- BusyBox-compatible scripts for embedded and container environments\n- Package distributions for various platforms without bash dependency\n\n## Essential Tools\n\n### Static Analysis & Formatting\n- **ShellCheck**: Static analyzer with `-s sh` for POSIX mode validation\n- **shfmt**: Shell formatter with `-ln posix` option for POSIX syntax\n- **checkbashisms**: Detects bash-specific constructs in scripts (from devscripts)\n- **Semgrep**: SAST with POSIX-specific security rules\n- **CodeQL**: Security scanning for shell scripts\n\n### POSIX Shell Implementations for Testing\n- **dash**: Debian Almquist Shell - lightweight, strict POSIX compliance (primary test target)\n- **ash**: Almquist Shell - BusyBox default, embedded systems\n- **yash**: Yet Another Shell - strict POSIX conformance validation\n- **posh**: Policy-compliant Ordinary Shell - Debian policy compliance\n- **osh**: Oil Shell - modern POSIX-compatible shell with better error messages\n- **bash --posix**: GNU Bash in POSIX mode for compatibility testing\n\n### Testing Frameworks\n- **bats-core**: Bash testing framework (works with POSIX sh)\n- **shellspec**: BDD-style testing that supports POSIX sh\n- **shunit2**: xUnit-style framework with POSIX sh support\n- **sharness**: Test framework used by Git (POSIX-compatible)\n\n## Common Pitfalls to Avoid\n\n- Using `[[` instead of `[` (bash-specific)\n- Using arrays (not in POSIX sh)\n- Using `local` keyword (bash\u002Fksh extension)\n- Using `echo` without `printf` (behavior varies across implementations)\n- Using `source` instead of `.` for sourcing scripts\n- Using bash-specific parameter expansion: `${var\u002F\u002Fpattern\u002Freplacement}`\n- Using process substitution `\u003C()` or `>()`\n- Using `function` keyword (ksh\u002Fbash syntax)\n- Using `$RANDOM` variable (not in POSIX)\n- Using `read -a` for arrays (bash-specific)\n- Using `set -o pipefail` (bash-specific)\n- Using `&>` for redirection (use `>file 2>&1`)\n\n## Advanced Techniques\n\n- **Error Trapping**: `trap 'echo \"Error at line $LINENO\" >&2; exit 1' EXIT; trap - EXIT` on success\n- **Safe Temp Files**: `tmpfile=$(mktemp) || exit 1; trap 'rm -f \"$tmpfile\"' EXIT INT TERM`\n- **Simulating Arrays**: `set -- item1 item2 item3; for arg; do process \"$arg\"; done`\n- **Field Parsing**: `IFS=:; while read -r user pass uid gid; do ...; done \u003C \u002Fetc\u002Fpasswd`\n- **String Replacement**: `echo \"$str\" | sed 's\u002Fold\u002Fnew\u002Fg'` or use parameter expansion `${str%suffix}`\n- **Default Values**: `value=${var:-default}` assigns default if var unset or null\n- **Portable Functions**: Avoid `function` keyword, use `func_name() { ... }`\n- **Subshell Isolation**: `(cd dir && cmd)` changes directory without affecting parent\n- **Here-documents**: `cat \u003C\u003C'EOF'` with quotes prevents variable expansion\n- **Command Existence**: `command -v cmd >\u002Fdev\u002Fnull 2>&1 && echo \"found\" || echo \"missing\"`\n\n## POSIX-Specific Best Practices\n\n- Always quote variable expansions: `\"$var\"` not `$var`\n- Use `[ ]` with proper spacing: `[ \"$a\" = \"$b\" ]` not `[\"$a\"=\"$b\"]`\n- Use `=` for string comparison, not `==` (bash extension)\n- Use `.` for sourcing, not `source`\n- Use `printf` for all output, avoid `echo -e` or `echo -n`\n- Use `$(( ))` for arithmetic, not `let` or `declare -i`\n- Use `case` for pattern matching, not `[[ =~ ]]`\n- Test scripts with `sh -n script.sh` to check syntax\n- Use `command -v` not `type` or `which` for portability\n- Explicitly handle all error conditions with `|| exit 1`\n\n## References & Further Reading\n\n### POSIX Standards & Specifications\n- [POSIX Shell Command Language](https:\u002F\u002Fpubs.opengroup.org\u002Fonlinepubs\u002F9699919799\u002Futilities\u002FV3_chap02.html) - Official POSIX.1-2024 specification\n- [POSIX Utilities](https:\u002F\u002Fpubs.opengroup.org\u002Fonlinepubs\u002F9699919799\u002Fidx\u002Futilities.html) - Complete list of POSIX-mandated utilities\n- [Autoconf Portable Shell Programming](https:\u002F\u002Fwww.gnu.org\u002Fsoftware\u002Fautoconf\u002Fmanual\u002Fautoconf.html#Portable-Shell) - Comprehensive portability guide from GNU\n\n### Portability & Best Practices\n- [Rich's sh (POSIX shell) tricks](http:\u002F\u002Fwww.etalabs.net\u002Fsh_tricks.html) - Advanced POSIX shell techniques\n- [Suckless Shell Style Guide](https:\u002F\u002Fsuckless.org\u002Fcoding_style\u002F) - Minimalist POSIX sh patterns\n- [FreeBSD Porter's Handbook - Shell](https:\u002F\u002Fdocs.freebsd.org\u002Fen\u002Fbooks\u002Fporters-handbook\u002Fmakefiles\u002F#porting-shlibs) - BSD portability considerations\n\n### Tools & Testing\n- [checkbashisms](https:\u002F\u002Fmanpages.debian.org\u002Ftesting\u002Fdevscripts\u002Fcheckbashisms.1.en.html) - Detect bash-specific constructs\n","## Use this skill when\n\n- Working on posix shell pro tasks or workflows\n- Needing guidance, best practices, or checklists for posix shell pro\n\n## Do not use this skill when\n\n- The task is unrelated to posix shell pro\n- You need a different domain or tool outside this scope\n\n## Instructions\n\n- Clarify goals, constraints, and required inputs.\n- Apply relevant best practices and validate outcomes.\n- Provide actionable steps and verification.\n- If detailed examples are required, open `resources\u002Fimplementation-playbook.md`.\n\n## Focus Areas\n\n- Strict POSIX compliance for maximum portability\n- Shell-agnostic scripting that works on any Unix-like system\n- Defensive programming with portable error handling\n- Safe argument parsing without bash-specific features\n- Portable file operations and resource management\n- Cross-platform compatibility (Linux, BSD, Solaris, AIX, macOS)\n- Testing with dash, ash, and POSIX mode validation\n- Static analysis with ShellCheck in POSIX mode\n- Minimalist approach using only POSIX-specified features\n- Compatibility with legacy systems and embedded environments\n\n## POSIX Constraints\n\n- No arrays (use positional parameters or delimited strings)\n- No `[[` conditionals (use `[` test command only)\n- No process substitution `\u003C()` or `>()`\n- No brace expansion `{1..10}`\n- No `local` keyword (use function-scoped variables carefully)\n- No `declare`, `typeset`, or `readonly` for variable attributes\n- No `+=` operator for string concatenation\n- No `${var\u002F\u002Fpattern\u002Freplacement}` substitution\n- No associative arrays or hash tables\n- No `source` command (use `.` for sourcing files)\n\n## Approach\n\n- Always use `#!\u002Fbin\u002Fsh` shebang for POSIX shell\n- Use `set -eu` for error handling (no `pipefail` in POSIX)\n- Quote all variable expansions: `\"$var\"` never `$var`\n- Use `[ ]` for all conditional tests, never `[[`\n- Implement argument parsing with `while` and `case` (no `getopts` for long options)\n- Create temporary files safely with `mktemp` and cleanup traps\n- Use `printf` instead of `echo` for all output (echo behavior varies)\n- Use `. script.sh` instead of `source script.sh` for sourcing\n- Implement error handling with explicit `|| exit 1` checks\n- Design scripts to be idempotent and support dry-run modes\n- Use `IFS` manipulation carefully and restore original value\n- Validate inputs with `[ -n \"$var\" ]` and `[ -z \"$var\" ]` tests\n- End option parsing with `--` and use `rm -rf -- \"$dir\"` for safety\n- Use command substitution `$()` instead of backticks for readability\n- Implement structured logging with timestamps using `date`\n- Test scripts with dash\u002Fash to verify POSIX compliance\n\n## Compatibility & Portability\n\n- Use `#!\u002Fbin\u002Fsh` to invoke the system's POSIX shell\n- Test on multiple shells: dash (Debian\u002FUbuntu default), ash (Alpine\u002FBusyBox), bash --posix\n- Avoid GNU-specific options; use POSIX-specified flags only\n- Handle platform differences: `uname -s` for OS detection\n- Use `command -v` instead of `which` (more portable)\n- Check for command availability: `command -v cmd >\u002Fdev\u002Fnull 2>&1 || exit 1`\n- Provide portable implementations for missing utilities\n- Use `[ -e \"$file\" ]` for existence checks (works on all systems)\n- Avoid `\u002Fdev\u002Fstdin`, `\u002Fdev\u002Fstdout` (not universally available)\n- Use explicit redirection instead of `&>` (bash-specific)\n\n## Readability & Maintainability\n\n- Use descriptive variable names in UPPER_CASE for exports, lower_case for locals\n- Add section headers with comment blocks for organization\n- Keep functions under 50 lines; extract complex logic\n- Use consistent indentation (spaces only, typically 2 or 4)\n- Document function purpose and parameters in comments\n- Use meaningful names: `validate_input` not `check`\n- Add comments for non-obvious POSIX workarounds\n- Group related functions with descriptive headers\n- Extract repeated code into functions\n- Use blank lines to separate logical sections\n\n## Safety & Security Patterns\n\n- Quote all variable expansions to prevent word splitting\n- Validate file permissions before operations: `[ -r \"$file\" ] || exit 1`\n- Sanitize user input before using in commands\n- Validate numeric input: `case $num in *[!0-9]*) exit 1 ;; esac`\n- Never use `eval` on untrusted input\n- Use `--` to separate options from arguments: `rm -- \"$file\"`\n- Validate required variables: `[ -n \"$VAR\" ] || { echo \"VAR required\" >&2; exit 1; }`\n- Check exit codes explicitly: `cmd || { echo \"failed\" >&2; exit 1; }`\n- Use `trap` for cleanup: `trap 'rm -f \"$tmpfile\"' EXIT INT TERM`\n- Set restrictive umask for sensitive files: `umask 077`\n- Log security-relevant operations to syslog or file\n- Validate file paths don't contain unexpected characters\n- Use full paths for commands in security-critical scripts: `\u002Fbin\u002Frm` not `rm`\n\n## Performance Optimization\n\n- Use shell built-ins over external commands when possible\n- Avoid spawning subshells in loops: use `while read` not `for i in $(cat)`\n- Cache command results in variables instead of repeated execution\n- Use `case` for multiple string comparisons (faster than repeated `if`)\n- Process files line-by-line for large files\n- Use `expr` or `$(( ))` for arithmetic (POSIX supports `$(( ))`)\n- Minimize external command calls in tight loops\n- Use `grep -q` when you only need true\u002Ffalse (faster than capturing output)\n- Batch similar operations together\n- Use here-documents for multi-line strings instead of multiple echo calls\n\n## Documentation Standards\n\n- Implement `-h` flag for help (avoid `--help` without proper parsing)\n- Include usage message showing synopsis and options\n- Document required vs optional arguments clearly\n- List exit codes: 0=success, 1=error, specific codes for specific failures\n- Document prerequisites and required commands\n- Add header comment with script purpose and author\n- Include examples of common usage patterns\n- Document environment variables used by script\n- Provide troubleshooting guidance for common issues\n- Note POSIX compliance in documentation\n\n## Working Without Arrays\n\nSince POSIX sh lacks arrays, use these patterns:\n\n- **Positional Parameters**: `set -- item1 item2 item3; for arg; do echo \"$arg\"; done`\n- **Delimited Strings**: `items=\"a:b:c\"; IFS=:; set -- $items; IFS=' '`\n- **Newline-Separated**: `items=\"a\\nb\\nc\"; while IFS= read -r item; do echo \"$item\"; done \u003C\u003CEOF`\n- **Counters**: `i=0; while [ $i -lt 10 ]; do i=$((i+1)); done`\n- **Field Splitting**: Use `cut`, `awk`, or parameter expansion for string splitting\n\n## Portable Conditionals\n\nUse `[ ]` test command with POSIX operators:\n\n- **File Tests**: `[ -e file ]` exists, `[ -f file ]` regular file, `[ -d dir ]` directory\n- **String Tests**: `[ -z \"$str\" ]` empty, `[ -n \"$str\" ]` not empty, `[ \"$a\" = \"$b\" ]` equal\n- **Numeric Tests**: `[ \"$a\" -eq \"$b\" ]` equal, `[ \"$a\" -lt \"$b\" ]` less than\n- **Logical**: `[ cond1 ] && [ cond2 ]` AND, `[ cond1 ] || [ cond2 ]` OR\n- **Negation**: `[ ! -f file ]` not a file\n- **Pattern Matching**: Use `case` not `[[ =~ ]]`\n\n## CI\u002FCD Integration\n\n- **Matrix testing**: Test across dash, ash, bash --posix, yash on Linux, macOS, Alpine\n- **Container testing**: Use alpine:latest (ash), debian:stable (dash) for reproducible tests\n- **Pre-commit hooks**: Configure checkbashisms, shellcheck -s sh, shfmt -ln posix\n- **GitHub Actions**: Use shellcheck-problem-matchers with POSIX mode\n- **Cross-platform validation**: Test on Linux, macOS, FreeBSD, NetBSD\n- **BusyBox testing**: Validate on BusyBox environments for embedded systems\n- **Automated releases**: Tag versions and generate portable distribution packages\n- **Coverage tracking**: Ensure test coverage across all POSIX shells\n- Example workflow: `shellcheck -s sh *.sh && shfmt -ln posix -d *.sh && checkbashisms *.sh`\n\n## Embedded Systems & Limited Environments\n\n- **BusyBox compatibility**: Test with BusyBox's limited ash implementation\n- **Alpine Linux**: Default shell is BusyBox ash, not bash\n- **Resource constraints**: Minimize memory usage, avoid spawning excessive processes\n- **Missing utilities**: Provide fallbacks when common tools unavailable (`mktemp`, `seq`)\n- **Read-only filesystems**: Handle scenarios where `\u002Ftmp` may be restricted\n- **No coreutils**: Some environments lack GNU coreutils extensions\n- **Signal handling**: Limited signal support in minimal environments\n- **Startup scripts**: Init scripts must be POSIX for maximum compatibility\n- Example: Check for mktemp: `command -v mktemp >\u002Fdev\u002Fnull 2>&1 || mktemp() { ... }`\n\n## Migration from Bash to POSIX sh\n\n- **Assessment**: Run `checkbashisms` to identify bash-specific constructs\n- **Array elimination**: Convert arrays to delimited strings or positional parameters\n- **Conditional updates**: Replace `[[` with `[` and adjust regex to `case` patterns\n- **Local variables**: Remove `local` keyword, use function prefixes instead\n- **Process substitution**: Replace `\u003C()` with temporary files or pipes\n- **Parameter expansion**: Use `sed`\u002F`awk` for complex string manipulation\n- **Testing strategy**: Incremental conversion with continuous validation\n- **Documentation**: Note any POSIX limitations or workarounds\n- **Gradual migration**: Convert one function at a time, test thoroughly\n- **Fallback support**: Maintain dual implementations during transition if needed\n\n## Quality Checklist\n\n- Scripts pass ShellCheck with `-s sh` flag (POSIX mode)\n- Code is formatted consistently with shfmt using `-ln posix`\n- Test on multiple shells: dash, ash, bash --posix, yash\n- All variable expansions are properly quoted\n- No bash-specific features used (arrays, `[[`, `local`, etc.)\n- Error handling covers all failure modes\n- Temporary resources cleaned up with EXIT trap\n- Scripts provide clear usage information\n- Input validation prevents injection attacks\n- Scripts portable across Unix-like systems (Linux, BSD, Solaris, macOS, Alpine)\n- BusyBox compatibility validated for embedded use cases\n- No GNU-specific extensions or flags used\n\n## Output\n\n- POSIX-compliant shell scripts maximizing portability\n- Test suites using shellspec or bats-core validating across dash, ash, yash\n- CI\u002FCD configurations for multi-shell matrix testing\n- Portable implementations of common patterns with fallbacks\n- Documentation on POSIX limitations and workarounds with examples\n- Migration guides for converting bash scripts to POSIX sh incrementally\n- Cross-platform compatibility matrices (Linux, BSD, macOS, Solaris, Alpine)\n- Performance benchmarks comparing different POSIX shells\n- Fallback implementations for missing utilities (mktemp, seq, timeout)\n- BusyBox-compatible scripts for embedded and container environments\n- Package distributions for various platforms without bash dependency\n\n## Essential Tools\n\n### Static Analysis & Formatting\n- **ShellCheck**: Static analyzer with `-s sh` for POSIX mode validation\n- **shfmt**: Shell formatter with `-ln posix` option for POSIX syntax\n- **checkbashisms**: Detects bash-specific constructs in scripts (from devscripts)\n- **Semgrep**: SAST with POSIX-specific security rules\n- **CodeQL**: Security scanning for shell scripts\n\n### POSIX Shell Implementations for Testing\n- **dash**: Debian Almquist Shell - lightweight, strict POSIX compliance (primary test target)\n- **ash**: Almquist Shell - BusyBox default, embedded systems\n- **yash**: Yet Another Shell - strict POSIX conformance validation\n- **posh**: Policy-compliant Ordinary Shell - Debian policy compliance\n- **osh**: Oil Shell - modern POSIX-compatible shell with better error messages\n- **bash --posix**: GNU Bash in POSIX mode for compatibility testing\n\n### Testing Frameworks\n- **bats-core**: Bash testing framework (works with POSIX sh)\n- **shellspec**: BDD-style testing that supports POSIX sh\n- **shunit2**: xUnit-style framework with POSIX sh support\n- **sharness**: Test framework used by Git (POSIX-compatible)\n\n## Common Pitfalls to Avoid\n\n- Using `[[` instead of `[` (bash-specific)\n- Using arrays (not in POSIX sh)\n- Using `local` keyword (bash\u002Fksh extension)\n- Using `echo` without `printf` (behavior varies across implementations)\n- Using `source` instead of `.` for sourcing scripts\n- Using bash-specific parameter expansion: `${var\u002F\u002Fpattern\u002Freplacement}`\n- Using process substitution `\u003C()` or `>()`\n- Using `function` keyword (ksh\u002Fbash syntax)\n- Using `$RANDOM` variable (not in POSIX)\n- Using `read -a` for arrays (bash-specific)\n- Using `set -o pipefail` (bash-specific)\n- Using `&>` for redirection (use `>file 2>&1`)\n\n## Advanced Techniques\n\n- **Error Trapping**: `trap 'echo \"Error at line $LINENO\" >&2; exit 1' EXIT; trap - EXIT` on success\n- **Safe Temp Files**: `tmpfile=$(mktemp) || exit 1; trap 'rm -f \"$tmpfile\"' EXIT INT TERM`\n- **Simulating Arrays**: `set -- item1 item2 item3; for arg; do process \"$arg\"; done`\n- **Field Parsing**: `IFS=:; while read -r user pass uid gid; do ...; done \u003C \u002Fetc\u002Fpasswd`\n- **String Replacement**: `echo \"$str\" | sed 's\u002Fold\u002Fnew\u002Fg'` or use parameter expansion `${str%suffix}`\n- **Default Values**: `value=${var:-default}` assigns default if var unset or null\n- **Portable Functions**: Avoid `function` keyword, use `func_name() { ... }`\n- **Subshell Isolation**: `(cd dir && cmd)` changes directory without affecting parent\n- **Here-documents**: `cat \u003C\u003C'EOF'` with quotes prevents variable expansion\n- **Command Existence**: `command -v cmd >\u002Fdev\u002Fnull 2>&1 && echo \"found\" || echo \"missing\"`\n\n## POSIX-Specific Best Practices\n\n- Always quote variable expansions: `\"$var\"` not `$var`\n- Use `[ ]` with proper spacing: `[ \"$a\" = \"$b\" ]` not `[\"$a\"=\"$b\"]`\n- Use `=` for string comparison, not `==` (bash extension)\n- Use `.` for sourcing, not `source`\n- Use `printf` for all output, avoid `echo -e` or `echo -n`\n- Use `$(( ))` for arithmetic, not `let` or `declare -i`\n- Use `case` for pattern matching, not `[[ =~ ]]`\n- Test scripts with `sh -n script.sh` to check syntax\n- Use `command -v` not `type` or `which` for portability\n- Explicitly handle all error conditions with `|| exit 1`\n\n## References & Further Reading\n\n### POSIX Standards & Specifications\n- [POSIX Shell Command Language](https:\u002F\u002Fpubs.opengroup.org\u002Fonlinepubs\u002F9699919799\u002Futilities\u002FV3_chap02.html) - Official POSIX.1-2024 specification\n- [POSIX Utilities](https:\u002F\u002Fpubs.opengroup.org\u002Fonlinepubs\u002F9699919799\u002Fidx\u002Futilities.html) - Complete list of POSIX-mandated utilities\n- [Autoconf Portable Shell Programming](https:\u002F\u002Fwww.gnu.org\u002Fsoftware\u002Fautoconf\u002Fmanual\u002Fautoconf.html#Portable-Shell) - Comprehensive portability guide from GNU\n\n### Portability & Best Practices\n- [Rich's sh (POSIX shell) tricks](http:\u002F\u002Fwww.etalabs.net\u002Fsh_tricks.html) - Advanced POSIX shell techniques\n- [Suckless Shell Style Guide](https:\u002F\u002Fsuckless.org\u002Fcoding_style\u002F) - Minimalist POSIX sh patterns\n- [FreeBSD Porter's Handbook - Shell](https:\u002F\u002Fdocs.freebsd.org\u002Fen\u002Fbooks\u002Fporters-handbook\u002Fmakefiles\u002F#porting-shlibs) - BSD portability considerations\n\n### Tools & Testing\n- [checkbashisms](https:\u002F\u002Fmanpages.debian.org\u002Ftesting\u002Fdevscripts\u002Fcheckbashisms.1.en.html) - Detect bash-specific constructs\n",{"name":5,"risk":26,"source":33,"date_added":43,"description":7},"2026-02-27","main","7a38d8e7073e61c16eda85681cb32fb68a8657a5","skills-store\u002Fcursor\u002Fposix-shell-pro","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router","https:\u002F\u002Fgithub.com\u002Fsapsapshen","2026-04-14 21:12:12",{"source":8,"skillName":5,"commands":51,"prompt":61,"zipAvailable":62},[52,55,58],{"tool":53,"command":54},"npx","npx skills add sapsapshen\u002Fai-memory-router --skill posix-shell-pro",{"tool":56,"command":57},"bunx","bunx skills add sapsapshen\u002Fai-memory-router --skill posix-shell-pro",{"tool":59,"command":60},"pnpm","pnpm dlx skills add sapsapshen\u002Fai-memory-router --skill posix-shell-pro","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fcursor\u002Fposix-shell-pro\u002FSKILL.md",true,[],[65,89,113,123,136,155],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":76,"publishedAt":38},"01M71ATQRKG48SH06FQ697T5G9","wechat-search","Search WeChat Official Account articles using OpenClaw's web search and fetch capabilities with compliance-focused design.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Fwechat-search-release\u002FSKILL.md",[71],{"categoryNo":72,"categoryName":73,"taxonomyType":74,"taxonomyTypeDesc":75},"01JBSEEDCAT000000000000037","律师与法务","PROFESSION","适用职业",[77,78,79,80,81,82,83,84,85,86,87,88],"wechat search","wechat","search","capabilities","openclaw","design","web search","compliance","web","official","fetch","with",{"skillNo":90,"name":91,"nameZh":6,"description":92,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":93,"categories":94,"keywords":95,"publishedAt":38},"01M71ATNAVGZB35PFYM2GC5N00","trend-tap","Real-time trending topics aggregator across 7 platforms (X\u002FTwitter, Reddit, Google Trends, Hacker News, Zhihu, Bilibili, Weibo). Trigger: when user says 'trend', 'trends', 'trend tap', '热点', '热搜', or asks what is trending\u002Fhot. Do NOT use web_search — this skill already fetches live data from all platforms with zero API keys.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Ftrend-tap\u002FSKILL.md",[],[96,97,98,99,35,100,79,101,102,103,104,105,106,107,108,109,110,111,32,112],"trend","trend tap","tap","api keys","time","trending","hacker","aggregator","do","when","brew","live","data","google","install","read","api",{"skillNo":114,"name":115,"nameZh":6,"description":116,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":117,"categories":118,"keywords":119,"publishedAt":38},"01M71ATJ9AM5KM15AA8PS302EB","trend-radar","Real-time trending topics aggregator across 7 platforms (X\u002FTwitter, Reddit, Google Trends, Hacker News, Zhihu, Bilibili, Weibo). Trigger: when user says 'trend', 'trends', 'trend pulse', '热点', '热搜', or asks what is trending\u002Fhot. Do NOT use web_search — this skill already fetches live data from all platforms with zero API keys.","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Ftrend-radar\u002FSKILL.md",[],[120,121,96,106,107,108,109,35,79,111,122,32,112,105,103,102,101,110,100,99],"trend radar","radar","pulse",{"skillNo":124,"name":125,"nameZh":6,"description":126,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":127,"categories":128,"keywords":129,"publishedAt":38},"01M71ATGF095N3EJM9G8SD0BB5","tech-news-daily","每日科技新闻汇——从全球多个 RSS 源抓取最新科技新闻，翻译（英→中）、去重、排版成每日简报。当用户询问科技新闻、科技新鲜事、每日科技、技术动态、Daily Tech News 或类似表达时触发此技能。","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Ftech-news-daily\u002FSKILL.md",[],[130,131,132,133,134,135],"news","tech","tech news daily","daily","rss","翻译",{"skillNo":137,"name":138,"nameZh":6,"description":139,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":140,"categories":141,"keywords":147,"publishedAt":38},"01M71ATFAEAMQ17M70NQNY7SR8","summarize","Summarize URLs or files with the summarize CLI (web, PDFs, images, audio, YouTube).","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Fsummarize\u002FSKILL.md",[142],{"categoryNo":143,"categoryName":144,"taxonomyType":145,"taxonomyTypeDesc":146},"01JBSEEDCAT000000000000021","资料检索与研究","SCENARIO","使用场景",[138,85,148,149,150,88,106,151,152,153,98,154,110],"Audio","cli","youtube","images","https","files","pdfs",{"skillNo":156,"name":157,"nameZh":6,"description":158,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":159,"categories":160,"keywords":161,"publishedAt":38},"01M71ATDNS3R0M4H936PACQAWZ","sonoscli","Control Sonos speakers (discover\u002Fstatus\u002Fplay\u002Fvolume\u002Fgroup).","https:\u002F\u002Fgithub.com\u002Fsapsapshen\u002Fai-memory-router\u002Fblob\u002Fmain\u002Fskills-store\u002Fopenclaw\u002Fsonoscli\u002FSKILL.md",[],[157,162,163,164,110,165,152,166,167,168,169,170],"status","play","go","latest","github","discover","control","cmd","volume"]