Function r_shquote::quote

source ·
pub fn quote(source: &str) -> String
Expand description

Quote string

This takes a string and quotes it according to POSIX Shell rules. The result can be passed to POSIX compatible shells and it will be interpreted as a single token. The unquote() operation implements the inverse.

Note that there is no canonical way to quote strings. There are infinite ways to quote a string. This implementation always quotes using sequences of single-quotes. This mimics what a lot of other implementations do. Furthermore, redundant quotes may be added, even thought a shorter output would be possible. This is again done to stay compatible with other existing implementations and make comparisons easier. Nevertheless, a caller must never try to predict the possible escaping and quoting done by this function.

Examples

assert_eq!(r_shquote::quote("foobar"), "'foobar'");