For stdin mode, $0 is the executable basename with the build suffix .exeor .wasm removed, so both backends report sh. Script paths and explicit-c command names retain their supplied value.
cli/sh interprets shell source in MoonBit. External commands execute as directchild requests with the shell's cwd and exported environment. Authorization isowned by the caller and runtime; the interpreter does not filter environmentnames or delegate complete scripts to a host shell.
The following describes version 0.2.1. Platform verification and exactMoonX publication evidence are tracked in thesupport record.The support record is the canonical release record.
sh -c SOURCE [NAME [ARG...]] executes a string. sh FILE [ARG...] executes afile. sh -s [ARG...] and a bare invocation read commands from stdin, executingcomplete commands before EOF without prompts. sh -i explicitly enables theline-oriented interactive session, including ENV, PS1/PS2 on stderr,multiline input and recovery after a syntax or expansion error.ENV is expanded as a single startup pathname: parameter, arithmetic and$(...) substitutions are supported without field splitting or globbing.Literal quote characters, repeated spaces and ordinary Windows pathbackslashes survive expansion; backslashes before $, backticks, ", \or a newline use double-quoted escape rules. Script sessions never load ENV.
Command input is read one byte at a time through public async Reader methods,so the parser does not prefetch bytes intended for read or a foreground child.The session retains variables, exported names, cwd, functions, positionalarguments and status. cd updates PWD/OLDPWD; -L and -P select logicaland physical directory traversal. Pipeline stages and substitutions receiveisolated variable/function state; their IO streams run concurrently.
The shared shell package provides an opaque Session with new, asynchronousfeed/finish, prompt, and load_startup. Feed returns NeedMoreInput,Completed(status) or Exit(status). Reader/Writer injection supports embeddingand testing. run remains compatible, and capture returns (status, stdout)without merging stderr.
The implementation includes quoting, local variables and explicit exports,IFS field splitting, */?/bracket pathname patterns, default/alternate/error/assignment parameter words, command substitution, pipelines, redirections,conditionals, case arms, loops, functions, grouping, positional parameters,shift, and set -e/-u. Command substitution removes trailing LF charactersonly, and a command consisting of assignments returns the last substitution'sstatus. Arithmetic supports integer literals/variables, parentheses, unaryoperators and the usual binary arithmetic, bitwise, comparison and logicaloperators; unsupported arithmetic syntax and division by zero fail explicitly.
Builtins include read [-r] NAME..., printf, test/[, ., continue, cd,pwd, export, unset, set, shift, return, break, exit, echo, :,true and false. Dot executes in the existing session. Read preserves theremaining fields in its final variable and reports EOF even when it assigns apartial final line.
This is a bounded shell, not a complete POSIX or Bash implementation. Inparticular, the printf builtin currently implements %s/%c/%b/%d/%i/%u/%o/%x/%X,%%, basic width/alignment and common ASCII escapes; unsupported conversionsfail explicitly. Test supports common string, integer, file-kind/access andsize predicates; compound expressions should use shell &&/||. Break andcontinue support one loop level. Arithmetic assignment, increment, ternaryoperators, fd duplication, backticks and background jobs are not supported.Here-documents retain their existing literal-body subset.
-i does not promise automatic TTY detection, raw mode, line editing, terminalresize events, recoverable Ctrl-C, or job control. Async 0.22.4 does not exposethe complete public terminal/process-group interfaces needed for thesebehaviors. exec, fg, bg, jobs and wait reject the request explicitly.See ADR-0007 for the terminal boundary.
The workspace runner's sh-interactive-session scenario verifies persistentopen stdin, ENV, PS1/PS2, immediate execution, multiline input, variables,functions, cwd, read, foreground input, error recovery, EOF and exit. Itsforeground helper reads one line in pure MoonBit. Run the prebuilt driver with--suite scenarios --case sh-interactive-session --backend native or wasm.See test instructions. The original probe isretained under docs/reports/2026-09-21-test-cleanup-evidence/repro/.
Standalone --version prints exactly sh 0.2.1 followed by onenewline. Standalone --help starts with Usage: sh, lists bothmetadata options, and ends with a newline. Both write to stdout, leave stdinunread, and exit with status 0. Exact-version publication and verificationremain recorded separately in the support record.