Help us shape the future of Go! Take the 2026 Go Developer Survey

shellsyntax

package
v0.0.0-...-c703685 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const Dynamic = "\x00"

Dynamic marks a shell word whose value is known only at runtime.

Variables

This section is empty.

Functions

func Args

func Args(words []*syntax.Word) ([]string, bool)

func BraceArgs

func BraceArgs(words []*syntax.Word) ([]string, bool)

BraceArgs expands bounded lexical braces before reading static arguments. It never resolves parameters, expands filesystem globs, or executes source. Source: libraries/commandanalysis/execscope/shell.go:1007:1028@2f371767.

func CommandName

func CommandName(name string) string

CommandName normalizes absolute executable paths without treating relative paths as known executables.

func CommandWord

func CommandWord(words []string) (int, bool)

CommandWord shares wrapper operand handling with embedded-script classification.

func EnvArgs

func EnvArgs(args []*syntax.Word) ([]*syntax.Word, string)

func ExecutableWord

func ExecutableWord(words []*syntax.Word) (int, bool)

ExecutableWord follows wrappers without confusing option operands with the command. Lookup-only command invocations stay unchanged.

func FilePath

func FilePath(directory, path string) string

func Heredoc

func Heredoc(redirect *syntax.Redirect, partial bool) (string, bool)

func InterpreterIdentity

func InterpreterIdentity(interpreter string) string

InterpreterIdentity normalizes an interpreter path for policy comparisons.

func IsBatch

func IsBatch(input string) bool

IsBatch recognizes interpreter boundaries outside incomplete shell constructs.

func IsDigits

func IsDigits(value string) bool

func Literal

func Literal(word *syntax.Word) (string, bool)

func LiteralCd

func LiteralCd(stmt *syntax.Stmt, directory string) (string, bool)

LiteralCd returns the directory a literal `cd` selects for later steps. Home-relative, previous-directory, and computed targets do not match.

func LiteralParts

func LiteralParts(parts []syntax.WordPart, quoted bool) bool

func Operand

func Operand(word *syntax.Word) (value string, glob bool, ok bool)

func PatternCall

func PatternCall(script string, statement *syntax.Stmt) ([]string, bool)

PatternCall returns unevaluated arguments from a simple foreground command. An empty source requires literal arguments; otherwise simple shell patterns and parameters retain their original spelling. Transparent env and timeout wrappers are removed from the copy, never from the executed source.

func PatternWord

func PatternWord(word *syntax.Word) bool

PatternWord recognizes shell patterns and simple parameter references without expanding them. Parameter operators and executable substitutions stay opaque.

func Sequence

func Sequence(statements []*syntax.Stmt) []*syntax.Stmt

Sequence flattens `a && b` chains into their steps.

func ShellErrexit

func ShellErrexit(statement *syntax.Stmt) (bool, bool)

ShellErrexit reports whether validated current-shell error options explicitly leave errexit enabled. Unspecified errexit is conservatively false.

func ShellOptions

func ShellOptions(statement *syntax.Stmt) bool

ShellOptions recognizes current-shell set options that neither change command resolution nor select a repository or directory. External wrappers stay opaque.

func ShellScript

func ShellScript(statement *syntax.Stmt) (string, bool)

ShellScript recognizes a literal shell -c script without positional arguments or redirects. Recognition does not execute the script or resolve executables.

func Split

func Split(input string) ([]string, error)

Split starts programs at column-zero interpreter headers outside shell constructs. Headers stay with their programs; all other source bytes remain unchanged. Only an omitted params directive inherits the preceding complete object.

func SplitSource

func SplitSource(input string) []string

SplitSource returns authored program slices without validating headers or expanding inherited directives. It is also suitable for unfinished display input.

func StatementSource

func StatementSource(stmt *syntax.Stmt, fallback string) string

StatementSource prints a statement that owns a noncontiguous heredoc body. Other statements keep the caller's source slice and separator policy.

func StaticWord

func StaticWord(word *syntax.Word) (string, bool)

StaticWord only unquotes literal text. In particular, expand must never see parameter, arithmetic, command, process, or pathname expansions here.

func StreamingStatements

func StreamingStatements(input, directory string) ([]*syntax.Stmt, string, bool, bool)

StreamingStatements parses display-only stock command input. It never expands shell values or authorizes execution. Recovery is limited to the parser's incomplete final construct so streaming cat and interpreter heredocs can become visible before the host completes the call.

func UnwrapEnv

func UnwrapEnv(statement *syntax.Stmt) *syntax.Stmt

UnwrapEnv removes command-resolution-preserving literal env arguments from a copied statement. Unsupported options, dynamic values and PATH changes stay intact.

func UnwrapMRun

func UnwrapMRun(statement *syntax.Stmt) *syntax.Stmt

UnwrapMRun removes valid literal mrun options from a display copy. Child arguments and redirections remain intact; this does not establish execution.

func UnwrapTimeout

func UnwrapTimeout(statement *syntax.Stmt) *syntax.Stmt

Unwrap only a display copy. Keep argument positions, redirections, and all host-owned source bytes; unsupported options and dynamic durations stay Run.

Types

type HeaderError

type HeaderError struct {
	Line int
	Err  error
}

HeaderError locates a rejected header in the submitted program. Line is one-based and counts CRLF as one line terminator, just like header parsing.

func (*HeaderError) Error

func (e *HeaderError) Error() string

func (*HeaderError) Unwrap

func (e *HeaderError) Unwrap() error

type Parsed

type Parsed struct {
	Interpreter []string       `json:"interpreter,omitempty"`
	Body        string         `json:"body,omitempty"`
	Params      map[string]any `json:"params"`
	ParamsLine  int            `json:"paramsLine,omitempty"`
	HasParams   bool           `json:"hasParams,omitzero"`
}

Parsed is the portable shell header result.

func Parse

func Parse(input string) (Parsed, error)

Parse reads the portable interpreter selector and shell directives.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL