Documentation
¶
Overview ¶
Package shellsplit cuts a command line into the commands a shell would run, by that shell's own rules: what separates two commands, what quotes and escapes hide a separator, which text is data rather than a command (a heredoc body, a here-string, a comment), and which code is nested inside a command (command substitution, a PowerShell subexpression or script block, a heredoc body that is expanded or fed to an interpreter).
It is for scoring, not for executing: a nested command is returned as a command of its own as well as inside the one that holds it, and a line the rules can't finish (an unclosed quote) still yields what was read. Where the rules are ambiguous it errs toward showing a command, never toward hiding one.
scripts/shellsplit.py is a line-by-line port; testdata/golden.jsonl holds the two to the same output.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Parsed ¶
type Parsed struct {
// Commands, in order, each trimmed; nested ones follow the one holding them.
Commands []string
// Groups are commands joined by | || && (|& in sh) into one unit with two
// or more members — a pipeline's danger can be in the joining (`curl … | sh`).
Groups []string
// Code is the line without its data — heredoc bodies, PowerShell
// here-strings, comments — with its commands and the operators between
// them. (A sh <<< here-string is one word of its command and stays.)
Code string
// Incomplete: code nested deeper than maxDepth, or past maxParses, was
// kept as text, not cut.
Incomplete bool
// contains filtered or unexported fields
}
Parsed is a line cut into what is scored.