Skip to content

Commit 6dd12d8

Browse files
committed
Update Readme
1 parent 102b1d3 commit 6dd12d8

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

README.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ set up the parent and child IO handles manually, like this in the
1515
[rust cookbook](https://rust-lang-nursery.github.io/rust-cookbook/os/external.html), which is often a tedious
1616
work.
1717

18-
A lot developers just choose shell(sh, bash, ...) scripts for such tasks, by using `<` to redirect input,
18+
A lot of developers just choose shell(sh, bash, ...) scripts for such tasks, by using `<` to redirect input,
1919
`>` to redirect output and '|' to pipe outputs. In my experience, this is **the only good parts** of shell script.
2020
You can find all kinds of pitfalls and mysterious tricks to make other parts of shell script work. As the shell
2121
scripts grow, they will ultimately be unmaintainable and no one wants to touch them any more.
2222

2323
This cmd_lib library is trying to provide the redirection and piping capabilities, and other facilities to make writing
24-
shell-script like tasks easily. For the [rust cookbook examples](https://rust-lang-nursry.github.io/rust-cookbook/os/external.html),
24+
shell-script like tasks easily without launching any shell. For the
25+
[rust cookbook examples](https://rust-lang-nursry.github.io/rust-cookbook/os/external.html),
2526
they can usually be implemented as one line of rust macro with the help of this library, as in the
2627
[examples/rust_cookbook_external.rs](https://github.com/rust-shell-script/rust_cmd_lib/blob/master/examples/rust_cookbook_external.rs).
2728
Since they are rust code, you can always rewrite them in rust natively in the future, if necessary without spawning external commands.
@@ -51,7 +52,8 @@ Since they are rust code, you can always rewrite them in rust natively in the fu
5152
ls oops;
5253
cat oops;
5354
}.is_err() {
54-
eprintln!("Run group command failed");
55+
// your error handling code
56+
...
5557
}
5658
```
5759

@@ -75,9 +77,13 @@ like $a or ${a} in `run_cmd!` or `run_fun!` macros.
7577
If they are part of string literals, you need to capture the declarations with `| a, b, ... |` at the macros'
7678
beginnings. e.g.
7779
```rust
78-
let msg = "I love rust";
79-
run_cmd!(echo $msg)?;
80-
run_cmd!(|msg| echo "This is the message: $msg")?;
80+
let dir = "my folder";
81+
run_cmd!(|dir| echo "Creating $dir at /tmp")?;
82+
run_cmd!(mkdir -p /tmp/$dir)?;
83+
84+
// or with group commands:
85+
let dir = "my folder";
86+
run_cmd!(echo "Creating $dir at /tmp"; mkdir -p /tmp/$dir)?;
8187
```
8288
You can consider "" as glue, so everything inside the quotes will be treated as a single atomic component.
8389

0 commit comments

Comments
 (0)