pub fn remove_shell_quotes(word: &str) -> (String, bool, Option<char>)Expand description
Perform POSIX quote removal on a single already-tokenized word.
A shell word may carry quotes anywhere inside it, not just wrapped around
the whole thing: label:'help wanted', --flag="a b" and a'b c'd are all
one word each. The shell strips the quote characters and concatenates the
quoted and unquoted pieces into a single argument. Our tokenizer keeps the
quotes in the word (so it can split correctly and hand a valid command back
to a real shell when needed); this function turns that raw word into the
literal value a built-in command should receive, exactly as /bin/sh would
(issue #48).
Rules mirrored from POSIX:
- Outside quotes, a backslash escapes the next character (it becomes
literal and loses any quoting role). On Windows the backslash is the
path separator, so an unquoted backslash is kept literal there — eating
it would corrupt paths such as
cd C:\Users\foo. - Inside
'...', every character is literal, including backslash. - Inside
"...", a backslash only escapes$,`,",\and newline; before anything else it stays a literal backslash.
Returns the quote-removed value, whether any quoting/escaping was applied, and the first quote character seen.