Yash-quote

yash-quote is a Rust library crate for quoting strings used in a POSIX shell script. This crate provides just one function: quote. It returns a quoted version of the argument string.

workflow

Usage

Add yash-quote as a dependency in your Cargo.toml.

rust use std::borrow::Cow::{Borrowed, Owned}; use yash_quote::quote; assert_eq!(quote("foo"), Borrowed("foo")); assert_eq!(quote(""), Owned::<str>("''".to_owned())); assert_eq!(quote("$foo"), Owned::<str>("'$foo'".to_owned())); assert_eq!(quote("'$foo'"), Owned::<str>(r#""'\$foo'""#.to_owned()));

License

MIT or Apache 2.0, at your option

Similar crates

For the reverse operation of quote, the yash-syntax crate provides the unquote function.