Skip to main content

shell_single_quote

Function shell_single_quote 

Source
pub fn shell_single_quote(v: &str) -> String
Expand description

Wrap v in POSIX single quotes so a shell reads it as exactly one literal word.

Inside single quotes a POSIX shell performs no expansion at all, so $, backticks, ", whitespace and newlines pass through untouched. The one character that cannot appear is ' itself; each is emitted as '\'' — close the quote, supply an escaped quote, reopen — which is why the result is always quoted rather than quoted-if-needed.

use anodizer_core::shell::shell_single_quote;
assert_eq!(shell_single_quote("it's"), r"'it'\''s'");