1# shell-words
2
3Process command line according to parsing rules of Unix shell.
4
5## Usage
6
7Add this to Cargo.toml:
8```toml
9[dependencies]
10shell-words = "1.0.0"
11```
12
13Add this to your crate:
14```rust
15extern crate shell_words;
16```
17
18## Examples
19
20### Split
21
22Compiling C source code into an executable as in default build rule found in GNU Make:
23
24```rust
25extern crate shell_words;
26
27use std::env::var;
28use std::process::Command;
29
30fn main() {
31    let cc = var("CC").unwrap_or_else(|_| "cc".to_owned());
32
33    let cflags = var("CFLAGS").unwrap_or_else(|_| String::new());
34    let cflags = shell_words::split(&cflags).expect("failed to parse CFLAGS");
35
36    let cppflags = var("CPPFLAGS").unwrap_or_else(|_| String::new());
37    let cppflags = shell_words::split(&cppflags).expect("failed to parse CPPFLAGS");
38
39    Command::new(cc)
40        .args(cflags)
41        .args(cppflags)
42        .args(&["-c", "a.c", "-o", "a.out"])
43        .spawn()
44        .expect("failed to start subprocess")
45        .wait()
46        .expect("failed to wait for subprocess");
47}
48```
49
50### Join
51
52Logging executed commands in format that can be readily copied and pasted to a shell:
53
54```rust
55extern crate shell_words;
56
57fn main() {
58    let argv = &["python", "-c", "print('Hello world!')"];
59
60    println!("Executing: {}", shell_words::join(argv));
61
62    std::process::Command::new(&argv[0])
63        .args(&argv[1..])
64        .spawn()
65        .expect("failed to start subprocess")
66        .wait()
67        .expect("failed to wait for subprocess");
68}
69```
70
71## Bugs
72
73Please report any issues at https://github.com/tmiasko/shell-words/issues.
74
75## License
76
77Licensed under either of
78
79 * Apache License, Version 2.0
80   ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
81 * MIT license
82   ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
83
84at your option.
85
86## Contribution
87
88Unless you explicitly state otherwise, any contribution intentionally submitted
89for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
90dual licensed as above, without any additional terms or conditions.
91