Skip to main content

escape_for_shell

Function escape_for_shell 

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

Escapes a string for safe use in single-quoted shell contexts.

Replaces single quotes with the pattern '"'"' which:

  1. Ends the current single-quoted string
  2. Adds an escaped single quote
  3. Starts a new single-quoted string

This is the standard POSIX-compliant method for escaping single quotes within single-quoted strings.

ยงExamples

use ssh_mcp::ssh::elevation::escape_for_shell;

assert_eq!(escape_for_shell("hello"), "hello");
assert_eq!(escape_for_shell("it's"), "it'\"'\"'s");
assert_eq!(escape_for_shell("a'b'c"), "a'\"'\"'b'\"'\"'c");