golang/go · error
missing command
Error message
missing command
What it means
Thrown at the end of parse() when the line produced prefixes, conditions, arguments, or a background marker but no command name (cmd.name == ""). A line that is entirely blank or a comment returns (nil, nil); a line that has modifiers but no actual command is a syntax error. The guard checks cmd.want, cmd.conds, cmd.rawArgs, and cmd.background.
Source
Thrown at src/cmd/internal/script/engine.go:452
i++ // skip over second ' before next iteration
continue
}
// ending a quoted chunk
rawArg = append(rawArg, argFragment{s: line[start:i], quoted: true})
start = i + 1
quoted = false
continue
}
// found character worth saving; make sure we're saving
if start < 0 {
start = i
}
}
if cmd.name == "" {
if cmd.want != "" || len(cmd.conds) > 0 || len(cmd.rawArgs) > 0 || cmd.background {
// The line contains a command prefix or suffix, but no actual command.
return nil, errors.New("missing command")
}
// The line is blank, or contains only a comment.
return nil, nil
}
if n := len(cmd.rawArgs); n > 0 {
last := cmd.rawArgs[n-1]
if len(last) == 1 && !last[0].quoted && last[0].s == "&" {
cmd.background = true
cmd.rawArgs = cmd.rawArgs[:n-1]
}
}
return cmd, nil
}
// expandArgs expands the shell variables in rawArgs and joins them to form the
// final arguments to pass to a command.View on GitHub (pinned to b6b368adc5)
Solutions
- Add the command after the prefix/condition: `! nonexistent-cmd` not `! `.
- Remove orphan prefixes/conditions/arguments if no command is intended (a truly blank line is fine).
- Re-check that the command name was not accidentally quoted into a different token position.
Example fix
// before ! # -> missing command // after ! nonexistent-binary arg
Defensive patterns
Strategy: validation
Validate before calling
// A line must have a command name if it carries any prefix/cond/arg/&.
func hasCommand(line string) bool {
t := strings.TrimSpace(line)
// strip leading ! ? and [cond] tokens
for strings.HasPrefix(t, "!") || strings.HasPrefix(t, "?") || (strings.HasPrefix(t, "[") && strings.Contains(t, "]")) {
if strings.HasPrefix(t, "[") {
t = strings.TrimSpace(t[strings.Index(t, "]")+1:])
} else {
t = strings.TrimSpace(t[1:])
}
}
return t != "" && t != "&"
} Type guard
func isMissingCommand(err error) bool {
return err != nil && err.Error() == "missing command"
} Try / catch
// Lint script lines so any prefix/condition/& is followed by a real command.
Prevention
- Always follow a prefix or condition with an actual command.
- Delete orphan prefixes/conditions rather than leaving them.
- Lint for lines ending in '&' with no command.
When it happens
Trigger: A script line like `! ` (negation prefix but no command), `[cond]` alone, `? ` with nothing after, or a trailing `&` background marker on an otherwise empty line, or arguments supplied without a command name.
Common situations: Script-test author writes a prefix expecting to continue on the same line and forgets the command, or deletes the command while leaving a condition/prefix during editing.
Related errors
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/1935edaf0e8c048f.
Report an issue: GitHub.