Expand description
Quoting of bytes printed inside a shell command for a person to run.
What:
Quoting of bytes that are printed inside a shell command for a person to copy and run.
Why:
A path or a kernel argument can hold spaces, quotes, ;, $(...) or bytes that are not UTF-8. Printed bare, a
pasted command runs whatever follows the separator or substitution, or passes the wrong arguments. A value of safe
characters is printed as it is; any other value is wrapped in single quotes (each single quote inside closed,
escaped and opened again); a value with a control character or a byte that is not UTF-8 is spelled in the ANSI-C
form $'...' of bash, zsh and ksh with those bytes written as \xHH escapes, so the printed text holds no control
character and no line break. The same rules as package/wg/cli-quicker/src/shell-quote.ts.
In TS you’d write (pseudocode):
shellQuote({ value: "it's" }); // "'it'\\''s'"Functions§
- shell_
quote - What:
Quote bytes so a POSIX shell (bash, zsh or ksh for the
$'...'form) reads them back as one word.&[u8]is a borrowed byte view; a path’s bytes come fromOsStrExt::as_bytes. Why: See the module description.