# Compatibility ## Authority The [Plan 9 rc manual](https://9p.io/magic/man2html/1/rc) defines the target language. The [Plan 9 port source](https://github.com/9fans/plan9port/tree/master/src/cmd/rc) resolves pattern behavior and other ambiguities. The suite compares [plan9port rc](https://github.com/9fans/plan9port/tree/master/src/cmd/rc) and [Rakitzis rc](https://github.com/rakitzis/rc). The adjacent `../rc` repository supplies Rakitzis rc. Its behavior does not override the Plan 9 language. Examples of deliberate differences from the Unix reference: - `*` includes hidden files, except `.` and `..`. - A nonempty list cannot concatenate with an empty list. - `[~class]` complements a character class. `!` has no special class meaning. - Backslash does not escape ordinary characters. - A successful command stores an empty string in `$status`. - `-s` prints failed command status. It does not select standard input. - A false `if` retains its condition's status. The Unix reference returns success when it skips the body. - Pattern matches use Unicode code points, not bytes. - A quoted join of an empty list supplies one empty word. - Subscripts consume decimal prefixes and skip selectors that name no elements. - `shift` consumes a signed decimal prefix. A nonnumeric count means zero, and an excessive count drains the list. - Here-documents use variable values from the input boundary, before assignments on the same command line. Here-documents in functions work. This removes a documented limitation of the original shell. This extension retains execution-time expansion inside functions, including repeated calls and imported definitions. ## POSIX adaptations Login mode reads `$home/.rcrc`, as Rakitzis rc does, instead of the Plan 9 path `$home/lib/profile`. Non-login shells do not read this file automatically. - External failures use numeric Unix status strings. - Signal deaths use the conventional `128 + signal` exit code. - Missing and nonexecutable commands use exit codes 127 and 126. Both references use exit code 1. - An arbitrary nonempty status string maps to Unix failure at process exit. - `$home` initially uses `HOME` when the environment lacks `home`. - `$path` initially uses `PATH` when the environment lacks `path`. - Process substitution uses `/dev/fd`. - The shell uses internal startup defaults instead of `/rc/lib/rcmain`. - `-m` selects an explicit initialization file. - `-n` checks syntax without execution, as a Unix compatibility extension. - `-p` and `-d` do nothing, as the Plan 9 manual specifies. - Pipelines store each numeric stage status, separated by `|`. Successful stages contribute empty strings. Unlike plan9port, rc2 retains the position of the first successful stage. - `rfork e` and `rfork f` preserve the existing POSIX isolation. - `rfork s` creates a process group. `E` clears exports, and `F` closes the descriptor table. - Interrupts in `. -i` recover at the nearest interactive source, including a source from process substitution. - Namespace flags `n`, `N`, and `m` produce an explicit error. The default `rfork` also requires namespace support. Function import accepts exactly one literal function definition with the expected name. The interpreter rejects extra commands and computed function names before execution. This restriction rejects command text outside the declared function body. The interpreter rejects NUL bytes in source text and command substitution. Unix argument vectors cannot represent embedded NUL bytes. ## Scope and limits The [conformance matrix](CONFORMANCE.md) maps manual sections and UNIX extensions to regression coverage. Coverage does not establish complete compatibility for every input. 1. The approved POSIX scope rejects Plan 9 namespace operations. 2. The approved UNIX extensions include `whatis -s/-f/-v/-p/-b` and `. -i file`. Optional reference add-ons remain excluded. 3. Job control requires a controlling terminal. `jobs`, `fg`, and `bg` are UNIX extensions, not Plan 9 commands. 4. Completion reads scalar variables but never executes input substitutions. Multivalue computed prefixes remain unsupported. 5. Script declarations support recursive subcommands. Metadata extraction requires one top-level declaration block. 6. Nesting limits reject syntax or execution deeper than 256 recursive levels. 7. Terminal width depends on libc and the terminal's Unicode display conventions. Grapheme boundaries use Unicode 18 data. 8. Runtime validation covers macOS arm64, Linux arm64, and Linux amd64 under Docker emulation. Other UNIX systems and architectures lack runtime validation. The editor supports wrapped lines, resize, complete multiline history, and grapheme movement. Persistent history uses the reference's opt-in `$history` convention, with owner-only regular files and locked appends. Resource-limit reports use raw bytes, seconds, or counts, rather than formatted suffixes. Default interactive termination uses normal cleanup. SIGKILL cannot permit terminal cleanup. Text, syntax, and transient values use safe-point reclamation. Active evaluations retain their pool prefixes. Live variables, functions, history, and status caches retain their referenced objects. Large active source files and live shell state still determine peak memory use. Background processes retain their status until `wait` consumes it. Signal functions run during input, command substitution, and child waits, as well as evaluator boundaries. Signal functions defer other signal functions until the current function returns. Source-file reads preserve partial input across signal interruptions. Signal functions can source another file before the interrupted read resumes. Interactive source input temporarily handles default interrupts and quits. It restores caller dispositions but preserves explicit trap changes. The Plan 9 [compiler](https://github.com/9fans/plan9port/blob/master/src/cmd/rc/code.c) emits `Xif` without a status reset. The [executor](https://github.com/9fans/plan9port/blob/master/src/cmd/rc/exec.c) skips a false body without changing `$status`. The false-`if` difference therefore follows the Plan 9 target, not an omitted UNIX feature. The test suite is a conformance corpus, not proof of complete compatibility. Performance results apply only to the measured workloads and host. ## Conformance decisions Plan9port's [`subwords`](https://github.com/9fans/plan9port/blob/master/src/cmd/rc/exec.c) consumes decimal prefixes and omits empty or reversed selections. Rc2 uses this behavior but bounds numbers to the list length instead of permitting integer overflow. Plan9port's [`execshift`](https://github.com/9fans/plan9port/blob/master/src/cmd/rc/simple.c) uses `atoi` and stops after the argument list becomes empty. Rc2 retains decimal-prefix conversion, including negative counts that drain the list. Nonnumeric and zero counts preserve the list. Rc2 bounds counts to the list length, so large input cannot overflow. Plan9port's [`readhere`](https://github.com/9fans/plan9port/blob/master/src/cmd/rc/here.c) substitutes variables before it executes the parsed input. Rc2 snapshots ordinary unquoted bodies at the complete-input boundary. Quoted bodies remain literal, and function bodies retain the extension above. The Plan 9 manual explicitly specifies `eval [arg ...]`, so an empty `eval` remains valid. Plan9port's `execeval` incorrectly requires an argument. This discrepancy follows the manual instead of the implementation. Tasks `tsk-23` through `tsk-26` record these decisions. `CONFORMANCE.md` records commands, counts, and reference identities.