Skip to main content

escape_for_double_quotes

Function escape_for_double_quotes 

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

Escape a value so it can sit inside "..." as literal text.

Backslash, dollar, backtick and double quote are the only characters the shell still interprets inside double quotes, so escaping them makes the value literal - the inner program (e.g. bash -c) sees the original text.

ยงExamples

use command_stream::quote::escape_for_double_quotes;

assert_eq!(escape_for_double_quotes("plain text"), "plain text");
assert_eq!(escape_for_double_quotes("$HOME"), "\\$HOME");