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.
- If detailed examples are required, open
resources/implementation-playbook.md.
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
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
local keyword (use function-scoped variables carefully)
- No
declare, typeset, or readonly for variable attributes
- No
+= operator for string concatenation
- No
${var//pattern/replacement} substitution
- No associative arrays or hash tables
- No
source command (use . for sourcing files)
Approach
- Always use
#!/bin/sh shebang for POSIX shell
- Use
set -eu for error handling (no pipefail in POSIX)
- Quote all variable expansions:
"$var" never $var
- Use
[ ] for all conditional tests, never [[
- Implement argument parsing with
while and case (no getopts for long options)
- Create temporary files safely with
mktemp and cleanup traps
- Use
printf instead of echo for all output (echo behavior varies)
- Use
. script.sh instead of source script.sh for sourcing
- Implement error handling with explicit
|| exit 1 checks
- Design scripts to be idempotent and support dry-run modes
- Use
IFS manipulation carefully and restore original value
- Validate inputs with
[ -n "$var" ] and [ -z "$var" ] tests
- End option parsing with
-- and use rm -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/sh to 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 -s for OS detection
- Use
command -v instead of which (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_input not check
- 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
eval on 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
trap for cleanup: trap 'rm -f "$tmpfile"' EXIT 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/rm not rm
Performance Optimization
- Use shell built-ins over external commands when possible
- Avoid spawning subshells in loops: use
while read not for i in $(cat)
- Cache command results in variables instead of repeated execution
- Use
case for multiple string comparisons (faster than repeated if)
- Process files line-by-line for large files
- Use
expr or $(( )) for arithmetic (POSIX supports $(( )))
- Minimize external command calls in tight loops
- Use
grep -q when 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
-h flag for help (avoid --help without 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:
items="a:b:c"; IFS=:; set -- $items; IFS=' '
- Newline-Separated:
items="a\nb\nc"; while IFS= read -r item; do echo "$item"; done <<EOF
- 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
case not [[ =~ ]]
CI/CD Integration
- Matrix testing: Test across dash, ash, bash --posix, yash on Linux, macOS, Alpine
- Container testing: Use alpine:latest (ash), debian:stable (dash) for reproducible tests
- 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
/tmp may be restricted
- No coreutils: Some environments lack GNU coreutils extensions
- Signal handling: Limited signal support in minimal environments
- Startup scripts: Init scripts must be POSIX for maximum compatibility
- Example: Check for mktemp:
command -v mktemp >/dev/null 2>&1 || mktemp() { ... }
Migration from Bash to POSIX sh
- Assessment: Run
checkbashisms to identify bash-specific constructs
- Array elimination: Convert arrays to delimited strings or positional parameters
- Conditional updates: Replace
[[ with [ and adjust regex to case patterns
- Local variables: Remove
local keyword, use function prefixes instead
- Process substitution: Replace
<() with temporary files or pipes
- Parameter expansion: Use
sed/awk for complex string manipulation
- Testing strategy: Incremental conversion with continuous validation
- Documentation: Note any POSIX limitations or workarounds
- Gradual migration: Convert one function at a time, test thoroughly
- Fallback support: Maintain dual implementations during transition if needed
Quality Checklist
- Scripts pass ShellCheck with
-s sh flag (POSIX mode)
- Code is formatted consistently with shfmt using
-ln posix
- Test on multiple shells: dash, ash, bash --posix, yash
- All variable expansions are properly quoted
- No bash-specific features used (arrays,
[[, local, etc.)
- Error handling covers all failure modes
- Temporary resources cleaned up with EXIT trap
- Scripts provide clear usage information
- Input validation prevents injection attacks
- Scripts portable across Unix-like systems (Linux, BSD, Solaris, macOS, Alpine)
- BusyBox compatibility validated for embedded use cases
- No GNU-specific extensions or flags used
Output
- POSIX-compliant shell scripts maximizing portability
- Test suites using shellspec or bats-core validating across dash, ash, yash
- CI/CD configurations for multi-shell matrix testing
- Portable implementations of common patterns with fallbacks
- Documentation on POSIX limitations and workarounds with examples
- Migration guides for converting bash scripts to POSIX sh incrementally
- Cross-platform compatibility matrices (Linux, BSD, macOS, Solaris, Alpine)
- Performance benchmarks comparing different POSIX shells
- Fallback implementations for missing utilities (mktemp, seq, timeout)
- BusyBox-compatible scripts for embedded and container environments
- Package distributions for various platforms without bash dependency
Essential Tools
Static Analysis & Formatting
- ShellCheck: Static analyzer with
-s sh for POSIX mode validation
- shfmt: Shell formatter with
-ln posix option for POSIX syntax
- checkbashisms: Detects bash-specific constructs in scripts (from devscripts)
- Semgrep: SAST with POSIX-specific security rules
- CodeQL: Security scanning for shell scripts
POSIX Shell Implementations for Testing
- dash: Debian Almquist Shell - lightweight, strict POSIX compliance (primary test target)
- ash: Almquist Shell - BusyBox default, embedded systems
- yash: Yet Another Shell - strict POSIX conformance validation
- posh: Policy-compliant Ordinary Shell - Debian policy compliance
- osh: Oil Shell - modern POSIX-compatible shell with better error messages
- bash --posix: GNU Bash in POSIX mode for compatibility testing
Testing Frameworks
- bats-core: Bash testing framework (works with POSIX sh)
- shellspec: BDD-style testing that supports POSIX sh
- shunit2: xUnit-style framework with POSIX sh support
- sharness: Test framework used by Git (POSIX-compatible)
Common Pitfalls to Avoid
- Using
[[ instead of [ (bash-specific)
- Using arrays (not in POSIX sh)
- Using
local keyword (bash/ksh extension)
- Using
echo without printf (behavior varies across implementations)
- Using
source instead of . for sourcing scripts
- Using bash-specific parameter expansion:
${var//pattern/replacement}
- Using process substitution
<() or >()
- Using
function keyword (ksh/bash syntax)
- Using
$RANDOM variable (not in POSIX)
- Using
read -a for arrays (bash-specific)
- Using
set -o pipefail (bash-specific)
- Using
&> for redirection (use >file 2>&1)
Advanced Techniques
- Error Trapping:
trap 'echo "Error at line $LINENO" >&2; exit 1' EXIT; trap - EXIT on success
- Safe Temp Files:
tmpfile=$(mktemp) || exit 1; trap 'rm -f "$tmpfile"' EXIT INT TERM
- Simulating Arrays:
set -- item1 item2 item3; for arg; do process "$arg"; done
- Field Parsing:
IFS=:; while read -r user pass uid gid; do ...; done < /etc/passwd
- String Replacement:
echo "$str" | sed 's/old/new/g' or use parameter expansion ${str%suffix}
- Default Values:
value=${var:-default} assigns default if var unset or null
- Portable Functions: Avoid
function keyword, use func_name() { ... }
- Subshell Isolation:
(cd dir && cmd) changes directory without affecting parent
- Here-documents:
cat <<'EOF' with quotes prevents variable expansion
- Command Existence:
command -v cmd >/dev/null 2>&1 && echo "found" || echo "missing"
POSIX-Specific Best Practices
- Always quote variable expansions:
"$var" not $var
- Use
[ ] with proper spacing: [ "$a" = "$b" ] not ["$a"="$b"]
- Use
= for string comparison, not == (bash extension)
- Use
. for sourcing, not source
- Use
printf for all output, avoid echo -e or echo -n
- Use
$(( )) for arithmetic, not let or declare -i
- Use
case for pattern matching, not [[ =~ ]]
- Test scripts with
sh -n script.sh to check syntax
- Use
command -v not type or which for portability
- Explicitly handle all error conditions with
|| exit 1
References & Further Reading
POSIX Standards & Specifications
Portability & Best Practices
Tools & Testing
AGI Framework Integration
Adapted for @techwavedev/agi-agent-kit
Original source: antigravity-awesome-skills
Memory-First Protocol
Retrieve prior deployment configurations, rollback procedures, and incident post-mortems. Avoid re-discovering infrastructure patterns.
# Check for prior infrastructure context before starting
python3 execution/memory_manager.py auto --query "deployment configuration and patterns for Posix Shell Pro"
Storing Results
After completing work, store infrastructure decisions for future sessions:
python3 execution/memory_manager.py store \
--content "Deployment pipeline: configured blue-green deployment with health checks on port 8080" \
--type technical --project <project> \
--tags posix-shell-pro devops
Multi-Agent Collaboration
Broadcast deployment changes so frontend and backend agents update their configurations accordingly.
python3 execution/cross_agent_context.py store \
--agent "<your-agent>" \
--action "Deployed infrastructure changes — updated CI/CD pipeline with new health check endpoints" \
--project <project>
Playbook Integration
Use the ship-saas-mvp or full-stack-deploy playbook to sequence this skill with testing, documentation, and deployment verification.
1---2name: posix-shell-pro3description: 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).4risk: unknown5source: community6date_added: '2026-02-27'7---89## Use this skill when1011- Working on posix shell pro tasks or workflows12- Needing guidance, best practices, or checklists for posix shell pro1314## Do not use this skill when1516- The task is unrelated to posix shell pro17- You need a different domain or tool outside this scope1819## Instructions2021- Clarify goals, constraints, and required inputs.22- Apply relevant best practices and validate outcomes.23- Provide actionable steps and verification.24- If detailed examples are required, open `resources/implementation-playbook.md`.2526## Focus Areas2728- Strict POSIX compliance for maximum portability29- Shell-agnostic scripting that works on any Unix-like system30- Defensive programming with portable error handling31- Safe argument parsing without bash-specific features32- Portable file operations and resource management33- Cross-platform compatibility (Linux, BSD, Solaris, AIX, macOS)34- Testing with dash, ash, and POSIX mode validation35- Static analysis with ShellCheck in POSIX mode36- Minimalist approach using only POSIX-specified features37- Compatibility with legacy systems and embedded environments3839## POSIX Constraints4041- No arrays (use positional parameters or delimited strings)42- No `[[` conditionals (use `[` test command only)43- No process substitution `<()` or `>()`44- No brace expansion `{1..10}`45- No `local` keyword (use function-scoped variables carefully)46- No `declare`, `typeset`, or `readonly` for variable attributes47- No `+=` operator for string concatenation48- No `${var//pattern/replacement}` substitution49- No associative arrays or hash tables50- No `source` command (use `.` for sourcing files)5152## Approach5354- Always use `#!/bin/sh` shebang for POSIX shell55- Use `set -eu` for error handling (no `pipefail` in POSIX)56- Quote all variable expansions: `"$var"` never `$var`57- Use `[ ]` for all conditional tests, never `[[`58- Implement argument parsing with `while` and `case` (no `getopts` for long options)59- Create temporary files safely with `mktemp` and cleanup traps60- Use `printf` instead of `echo` for all output (echo behavior varies)61- Use `. script.sh` instead of `source script.sh` for sourcing62- Implement error handling with explicit `|| exit 1` checks63- Design scripts to be idempotent and support dry-run modes64- Use `IFS` manipulation carefully and restore original value65- Validate inputs with `[ -n "$var" ]` and `[ -z "$var" ]` tests66- End option parsing with `--` and use `rm -rf -- "$dir"` for safety67- Use command substitution `$()` instead of backticks for readability68- Implement structured logging with timestamps using `date`69- Test scripts with dash/ash to verify POSIX compliance7071## Compatibility & Portability7273- Use `#!/bin/sh` to invoke the system's POSIX shell74- Test on multiple shells: dash (Debian/Ubuntu default), ash (Alpine/BusyBox), bash --posix75- Avoid GNU-specific options; use POSIX-specified flags only76- Handle platform differences: `uname -s` for OS detection77- Use `command -v` instead of `which` (more portable)78- Check for command availability: `command -v cmd >/dev/null 2>&1 || exit 1`79- Provide portable implementations for missing utilities80- Use `[ -e "$file" ]` for existence checks (works on all systems)81- Avoid `/dev/stdin`, `/dev/stdout` (not universally available)82- Use explicit redirection instead of `&>` (bash-specific)8384## Readability & Maintainability8586- Use descriptive variable names in UPPER_CASE for exports, lower_case for locals87- Add section headers with comment blocks for organization88- Keep functions under 50 lines; extract complex logic89- Use consistent indentation (spaces only, typically 2 or 4)90- Document function purpose and parameters in comments91- Use meaningful names: `validate_input` not `check`92- Add comments for non-obvious POSIX workarounds93- Group related functions with descriptive headers94- Extract repeated code into functions95- Use blank lines to separate logical sections9697## Safety & Security Patterns9899- Quote all variable expansions to prevent word splitting100- Validate file permissions before operations: `[ -r "$file" ] || exit 1`101- Sanitize user input before using in commands102- Validate numeric input: `case $num in *[!0-9]*) exit 1 ;; esac`103- Never use `eval` on untrusted input104- Use `--` to separate options from arguments: `rm -- "$file"`105- Validate required variables: `[ -n "$VAR" ] || { echo "VAR required" >&2; exit 1; }`106- Check exit codes explicitly: `cmd || { echo "failed" >&2; exit 1; }`107- Use `trap` for cleanup: `trap 'rm -f "$tmpfile"' EXIT INT TERM`108- Set restrictive umask for sensitive files: `umask 077`109- Log security-relevant operations to syslog or file110- Validate file paths don't contain unexpected characters111- Use full paths for commands in security-critical scripts: `/bin/rm` not `rm`112113## Performance Optimization114115- Use shell built-ins over external commands when possible116- Avoid spawning subshells in loops: use `while read` not `for i in $(cat)`117- Cache command results in variables instead of repeated execution118- Use `case` for multiple string comparisons (faster than repeated `if`)119- Process files line-by-line for large files120- Use `expr` or `$(( ))` for arithmetic (POSIX supports `$(( ))`)121- Minimize external command calls in tight loops122- Use `grep -q` when you only need true/false (faster than capturing output)123- Batch similar operations together124- Use here-documents for multi-line strings instead of multiple echo calls125126## Documentation Standards127128- Implement `-h` flag for help (avoid `--help` without proper parsing)129- Include usage message showing synopsis and options130- Document required vs optional arguments clearly131- List exit codes: 0=success, 1=error, specific codes for specific failures132- Document prerequisites and required commands133- Add header comment with script purpose and author134- Include examples of common usage patterns135- Document environment variables used by script136- Provide troubleshooting guidance for common issues137- Note POSIX compliance in documentation138139## Working Without Arrays140141Since POSIX sh lacks arrays, use these patterns:142143- **Positional Parameters**: `set -- item1 item2 item3; for arg; do echo "$arg"; done`144- **Delimited Strings**: `items="a:b:c"; IFS=:; set -- $items; IFS=' '`145- **Newline-Separated**: `items="a\nb\nc"; while IFS= read -r item; do echo "$item"; done <<EOF`146- **Counters**: `i=0; while [ $i -lt 10 ]; do i=$((i+1)); done`147- **Field Splitting**: Use `cut`, `awk`, or parameter expansion for string splitting148149## Portable Conditionals150151Use `[ ]` test command with POSIX operators:152153- **File Tests**: `[ -e file ]` exists, `[ -f file ]` regular file, `[ -d dir ]` directory154- **String Tests**: `[ -z "$str" ]` empty, `[ -n "$str" ]` not empty, `[ "$a" = "$b" ]` equal155- **Numeric Tests**: `[ "$a" -eq "$b" ]` equal, `[ "$a" -lt "$b" ]` less than156- **Logical**: `[ cond1 ] && [ cond2 ]` AND, `[ cond1 ] || [ cond2 ]` OR157- **Negation**: `[ ! -f file ]` not a file158- **Pattern Matching**: Use `case` not `[[ =~ ]]`159160## CI/CD Integration161162- **Matrix testing**: Test across dash, ash, bash --posix, yash on Linux, macOS, Alpine163- **Container testing**: Use alpine:latest (ash), debian:stable (dash) for reproducible tests164- **Pre-commit hooks**: Configure checkbashisms, shellcheck -s sh, shfmt -ln posix165- **GitHub Actions**: Use shellcheck-problem-matchers with POSIX mode166- **Cross-platform validation**: Test on Linux, macOS, FreeBSD, NetBSD167- **BusyBox testing**: Validate on BusyBox environments for embedded systems168- **Automated releases**: Tag versions and generate portable distribution packages169- **Coverage tracking**: Ensure test coverage across all POSIX shells170- Example workflow: `shellcheck -s sh *.sh && shfmt -ln posix -d *.sh && checkbashisms *.sh`171172## Embedded Systems & Limited Environments173174- **BusyBox compatibility**: Test with BusyBox's limited ash implementation175- **Alpine Linux**: Default shell is BusyBox ash, not bash176- **Resource constraints**: Minimize memory usage, avoid spawning excessive processes177- **Missing utilities**: Provide fallbacks when common tools unavailable (`mktemp`, `seq`)178- **Read-only filesystems**: Handle scenarios where `/tmp` may be restricted179- **No coreutils**: Some environments lack GNU coreutils extensions180- **Signal handling**: Limited signal support in minimal environments181- **Startup scripts**: Init scripts must be POSIX for maximum compatibility182- Example: Check for mktemp: `command -v mktemp >/dev/null 2>&1 || mktemp() { ... }`183184## Migration from Bash to POSIX sh185186- **Assessment**: Run `checkbashisms` to identify bash-specific constructs187- **Array elimination**: Convert arrays to delimited strings or positional parameters188- **Conditional updates**: Replace `[[` with `[` and adjust regex to `case` patterns189- **Local variables**: Remove `local` keyword, use function prefixes instead190- **Process substitution**: Replace `<()` with temporary files or pipes191- **Parameter expansion**: Use `sed`/`awk` for complex string manipulation192- **Testing strategy**: Incremental conversion with continuous validation193- **Documentation**: Note any POSIX limitations or workarounds194- **Gradual migration**: Convert one function at a time, test thoroughly195- **Fallback support**: Maintain dual implementations during transition if needed196197## Quality Checklist198199- Scripts pass ShellCheck with `-s sh` flag (POSIX mode)200- Code is formatted consistently with shfmt using `-ln posix`201- Test on multiple shells: dash, ash, bash --posix, yash202- All variable expansions are properly quoted203- No bash-specific features used (arrays, `[[`, `local`, etc.)204- Error handling covers all failure modes205- Temporary resources cleaned up with EXIT trap206- Scripts provide clear usage information207- Input validation prevents injection attacks208- Scripts portable across Unix-like systems (Linux, BSD, Solaris, macOS, Alpine)209- BusyBox compatibility validated for embedded use cases210- No GNU-specific extensions or flags used211212## Output213214- POSIX-compliant shell scripts maximizing portability215- Test suites using shellspec or bats-core validating across dash, ash, yash216- CI/CD configurations for multi-shell matrix testing217- Portable implementations of common patterns with fallbacks218- Documentation on POSIX limitations and workarounds with examples219- Migration guides for converting bash scripts to POSIX sh incrementally220- Cross-platform compatibility matrices (Linux, BSD, macOS, Solaris, Alpine)221- Performance benchmarks comparing different POSIX shells222- Fallback implementations for missing utilities (mktemp, seq, timeout)223- BusyBox-compatible scripts for embedded and container environments224- Package distributions for various platforms without bash dependency225226## Essential Tools227228### Static Analysis & Formatting229- **ShellCheck**: Static analyzer with `-s sh` for POSIX mode validation230- **shfmt**: Shell formatter with `-ln posix` option for POSIX syntax231- **checkbashisms**: Detects bash-specific constructs in scripts (from devscripts)232- **Semgrep**: SAST with POSIX-specific security rules233- **CodeQL**: Security scanning for shell scripts234235### POSIX Shell Implementations for Testing236- **dash**: Debian Almquist Shell - lightweight, strict POSIX compliance (primary test target)237- **ash**: Almquist Shell - BusyBox default, embedded systems238- **yash**: Yet Another Shell - strict POSIX conformance validation239- **posh**: Policy-compliant Ordinary Shell - Debian policy compliance240- **osh**: Oil Shell - modern POSIX-compatible shell with better error messages241- **bash --posix**: GNU Bash in POSIX mode for compatibility testing242243### Testing Frameworks244- **bats-core**: Bash testing framework (works with POSIX sh)245- **shellspec**: BDD-style testing that supports POSIX sh246- **shunit2**: xUnit-style framework with POSIX sh support247- **sharness**: Test framework used by Git (POSIX-compatible)248249## Common Pitfalls to Avoid250251- Using `[[` instead of `[` (bash-specific)252- Using arrays (not in POSIX sh)253- Using `local` keyword (bash/ksh extension)254- Using `echo` without `printf` (behavior varies across implementations)255- Using `source` instead of `.` for sourcing scripts256- Using bash-specific parameter expansion: `${var//pattern/replacement}`257- Using process substitution `<()` or `>()`258- Using `function` keyword (ksh/bash syntax)259- Using `$RANDOM` variable (not in POSIX)260- Using `read -a` for arrays (bash-specific)261- Using `set -o pipefail` (bash-specific)262- Using `&>` for redirection (use `>file 2>&1`)263264## Advanced Techniques265266- **Error Trapping**: `trap 'echo "Error at line $LINENO" >&2; exit 1' EXIT; trap - EXIT` on success267- **Safe Temp Files**: `tmpfile=$(mktemp) || exit 1; trap 'rm -f "$tmpfile"' EXIT INT TERM`268- **Simulating Arrays**: `set -- item1 item2 item3; for arg; do process "$arg"; done`269- **Field Parsing**: `IFS=:; while read -r user pass uid gid; do ...; done < /etc/passwd`270- **String Replacement**: `echo "$str" | sed 's/old/new/g'` or use parameter expansion `${str%suffix}`271- **Default Values**: `value=${var:-default}` assigns default if var unset or null272- **Portable Functions**: Avoid `function` keyword, use `func_name() { ... }`273- **Subshell Isolation**: `(cd dir && cmd)` changes directory without affecting parent274- **Here-documents**: `cat <<'EOF'` with quotes prevents variable expansion275- **Command Existence**: `command -v cmd >/dev/null 2>&1 && echo "found" || echo "missing"`276277## POSIX-Specific Best Practices278279- Always quote variable expansions: `"$var"` not `$var`280- Use `[ ]` with proper spacing: `[ "$a" = "$b" ]` not `["$a"="$b"]`281- Use `=` for string comparison, not `==` (bash extension)282- Use `.` for sourcing, not `source`283- Use `printf` for all output, avoid `echo -e` or `echo -n`284- Use `$(( ))` for arithmetic, not `let` or `declare -i`285- Use `case` for pattern matching, not `[[ =~ ]]`286- Test scripts with `sh -n script.sh` to check syntax287- Use `command -v` not `type` or `which` for portability288- Explicitly handle all error conditions with `|| exit 1`289290## References & Further Reading291292### POSIX Standards & Specifications293- [POSIX Shell Command Language](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html) - Official POSIX.1-2024 specification294- [POSIX Utilities](https://pubs.opengroup.org/onlinepubs/9699919799/idx/utilities.html) - Complete list of POSIX-mandated utilities295- [Autoconf Portable Shell Programming](https://www.gnu.org/software/autoconf/manual/autoconf.html#Portable-Shell) - Comprehensive portability guide from GNU296297### Portability & Best Practices298- [Rich's sh (POSIX shell) tricks](http://www.etalabs.net/sh_tricks.html) - Advanced POSIX shell techniques299- [Suckless Shell Style Guide](https://suckless.org/coding_style/) - Minimalist POSIX sh patterns300- [FreeBSD Porter's Handbook - Shell](https://docs.freebsd.org/en/books/porters-handbook/makefiles/#porting-shlibs) - BSD portability considerations301302### Tools & Testing303- [checkbashisms](https://manpages.debian.org/testing/devscripts/checkbashisms.1.en.html) - Detect bash-specific constructs304305---306307<!-- AGI-INTEGRATION-START -->308309## AGI Framework Integration310311> **Adapted for [@techwavedev/agi-agent-kit](https://www.npmjs.com/package/@techwavedev/agi-agent-kit)**312> Original source: [antigravity-awesome-skills](https://github.com/sickn33/antigravity-awesome-skills)313314### Memory-First Protocol315316Retrieve prior deployment configurations, rollback procedures, and incident post-mortems. Avoid re-discovering infrastructure patterns.317318```bash319# Check for prior infrastructure context before starting320python3 execution/memory_manager.py auto --query "deployment configuration and patterns for Posix Shell Pro"321```322323### Storing Results324325After completing work, store infrastructure decisions for future sessions:326327```bash328python3 execution/memory_manager.py store \329 --content "Deployment pipeline: configured blue-green deployment with health checks on port 8080" \330 --type technical --project <project> \331 --tags posix-shell-pro devops332```333334### Multi-Agent Collaboration335336Broadcast deployment changes so frontend and backend agents update their configurations accordingly.337338```bash339python3 execution/cross_agent_context.py store \340 --agent "<your-agent>" \341 --action "Deployed infrastructure changes — updated CI/CD pipeline with new health check endpoints" \342 --project <project>343```344345### Playbook Integration346347Use the `ship-saas-mvp` or `full-stack-deploy` playbook to sequence this skill with testing, documentation, and deployment verification.348349<!-- AGI-INTEGRATION-END -->