#shell #unix #word #split #quote

no-std shell-words

Process command line according to parsing rules of UNIX shell

4 releases (stable)

Uses old Rust 2015

1.1.1 Dec 10, 2025
1.1.0 Feb 6, 2022
1.0.0 May 6, 2020
0.1.0 Mar 9, 2018

#11 in Unix APIs

Download history 843427/week @ 2025-08-27 836352/week @ 2025-09-03 802813/week @ 2025-09-10 771927/week @ 2025-09-17 810795/week @ 2025-09-24 818250/week @ 2025-10-01 778324/week @ 2025-10-08 890789/week @ 2025-10-15 969912/week @ 2025-10-22 974694/week @ 2025-10-29 1021435/week @ 2025-11-05 1000785/week @ 2025-11-12 1052971/week @ 2025-11-19 836628/week @ 2025-11-26 1056683/week @ 2025-12-03 936589/week @ 2025-12-10

4,058,652 downloads per month
Used in 3,014 crates (438 directly)

MIT/Apache

19KB
362 lines

shell-words

Process command line according to parsing rules of Unix shell.

Usage

Add this to Cargo.toml:

[dependencies]
shell-words = "1.0.0"

Add this to your crate:

extern crate shell_words;

Examples

Split

Compiling C source code into an executable as in default build rule found in GNU Make:

extern crate shell_words;

use std::env::var;
use std::process::Command;

fn main() {
    let cc = var("CC").unwrap_or_else(|_| "cc".to_owned());

    let cflags = var("CFLAGS").unwrap_or_else(|_| String::new());
    let cflags = shell_words::split(&cflags).expect("failed to parse CFLAGS");

    let cppflags = var("CPPFLAGS").unwrap_or_else(|_| String::new());
    let cppflags = shell_words::split(&cppflags).expect("failed to parse CPPFLAGS");

    Command::new(cc)
        .args(cflags)
        .args(cppflags)
        .args(&["-c", "a.c", "-o", "a.out"])
        .spawn()
        .expect("failed to start subprocess")
        .wait()
        .expect("failed to wait for subprocess");
}

Join

Logging executed commands in format that can be readily copied and pasted to a shell:

extern crate shell_words;

fn main() {
    let argv = &["python", "-c", "print('Hello world!')"];

    println!("Executing: {}", shell_words::join(argv));

    std::process::Command::new(&argv[0])
        .args(&argv[1..])
        .spawn()
        .expect("failed to start subprocess")
        .wait()
        .expect("failed to wait for subprocess");
}

Bugs

Please report any issues at https://github.com/tmiasko/shell-words/issues.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

No runtime deps

Features