Skip to main content

shell_single_quote

Function shell_single_quote 

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

What: Safely single-quote an arbitrary string for POSIX shells.

Inputs:

  • s: Text to quote.

Output:

  • New string wrapped in single quotes, escaping embedded quotes via the '"'"' sequence.

Details:

  • Returns '' for empty input so the shell treats it as an empty argument.
  • Ported from Pacsea’s install/utils.rs.

§Example

use arch_toolkit::install::shell_single_quote;

assert_eq!(shell_single_quote("plain"), "'plain'");
assert_eq!(shell_single_quote("it's"), r#"'it'"'"'s'"#);
assert_eq!(shell_single_quote(""), "''");