Expand description
Shell syntax for the simulated sandbox: quoting, variables, globs, redirection, pipes and command lists.
A small, honest subset of POSIX sh, enough for lessons to teach what a real shell does with a line before any program runs. Parsing is pure: variable values come from a lookup closure, and globs are only marked here (the sandbox expands them against its own files).
Not supported, and reported as such: command substitution ($(...),
backticks), background jobs (&), here-documents, subshells.
Structs§
- Pipeline
- Commands joined by
| - Stage
- One command in a pipeline
- Word
- One word after quoting and variable expansion
Enums§
Constants§
- STATUS_
MARK - Stands for
$?in text expanded for a real shell:renderturns it back into"$?", which the shell fills in with a number as it runs. Private-use characters, so ordinary typing never produces it (and if it did, the worst it can become is that number).
Functions§
- fnmatch
- Pattern match without the shell’s hidden-file rule (as
find -namedoes) - glob_
match - Does
namematch the globpatternthe way the shell expands it? Supports*,?,[abc],[a-z]and[!abc]; a leading.must be matched explicitly, so*skips hidden files. - is_name
- Is this a valid shell variable name?
- parse
- Parse one line into pipelines joined by
;,&&and||. - render
- Write an expanded command list back as one line for a real
sh -c, quoted so the shell takes every word, value and file name literally and expands nothing a second time: no variables, no~, no globs (expand those before rendering). What a guard checks in this line is what runs. The one thing left for the shell isSTATUS_MARK, written as"$?". - split_
list - Split a line at unquoted
;,&&and||, without expanding anything, so each part can be expanded just before it runs (as sh does: inX=5; echo $Xthe echo sees 5). A comment ends the line.