Skip to main content

shell_quote

Function shell_quote 

Source
pub fn shell_quote(value: &str) -> String
Expand description

Render a string as one POSIX shell word. Bare when every character is safe unquoted; otherwise single-quoted, with embedded ' closed and re-opened the POSIX way ('\'').

A leading - forces quoting even though - is otherwise safe: an argument that starts with a dash is read as an option by whatever receives it. (Quoting alone does not save cd, which parses its argument after the shell strips quotes — callers printing a cd emit cd --.)

Lives here rather than beside its first caller because every message that interpolates a filesystem path into a command the reader is expected to run needs it, and the one that did not — the shape disclosure’s other-shape command — was unrunnable for anyone whose binary path contained a space.