5 releases (stable)

1.1.1 Nov 11, 2023
1.1.0 May 1, 2023
1.0.1 Jan 5, 2023
1.0.0 Feb 2, 2022
0.1.0 Dec 11, 2021

#226 in Command-line interface

Download history 40/week @ 2024-01-19 56/week @ 2024-01-26 62/week @ 2024-02-02 17/week @ 2024-02-09 38/week @ 2024-02-16 72/week @ 2024-02-23 79/week @ 2024-03-01 65/week @ 2024-03-08 41/week @ 2024-03-15 39/week @ 2024-03-22 30/week @ 2024-03-29 26/week @ 2024-04-05 46/week @ 2024-04-12 56/week @ 2024-04-19 252/week @ 2024-04-26 90/week @ 2024-05-03

444 downloads per month
Used in 4 crates (3 directly)

MIT/Apache

11KB
176 lines

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.

yash-quote at crates.io yash-quote at docs.rs Build status

Usage

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

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

  • r-shquote provides a function that always quotes using single quotes.
  • The quote function of the shell_words crate is similar but tries to return the argument unchanged if possible. Unlike yash-quote, it only supports ASCII characters.
  • snailquote is also similar but uses an original format that is not fully compatible with POSIX shells.
  • shell_quote returns a string escaped using Bash's $'...' notation.

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

No runtime deps