Hacker Newsnew | past | comments | ask | show | jobs | submit | rustshellscript's commentslogin



Here is the rust library with the “the only good parts” of bash/shell script: https://github.com/rust-shell-script/rust_cmd_lib


The only good part of sh/bash script is to run commands with piping/redirection support IMO,other than that I saw posts like this to explain sh/bash script’s puzzles/pitfalls all the time.

Maybe it is time to consider using rust instead: https://github.com/rust-shell-script/rust_cmd_lib ?


I'm not sure why you're downvoted, but thanks for the link! Coincidentally, I've been searching this kind of library in Rust for the past few days.


zsh is also doing the variable substitution better than bash. FYI, I just released rust_cmd_lib 1.0 recently, which can do variable substitution without any quotes: https://github.com/rust-shell-script/rust_cmd_lib


I have developed a similar library before: https://github.com/rust-shell-script/bash_cmd_lib/blob/maste... which can do temp files cleanup, different levels ofreporting and redirecting all error msgs into log file automatically.


Thanks Steve. I have studied the "200 lines" book a few days ago, but was still confused. Only after seeing your talks, everything becomes so much clearer. These talks should really be part of the "async book" :)


The code in the second one is explaining the code in the async book! So it sorta kinda is.


I have created a similar library for bash. However, there are more pitfalls related to errexit, see [1] and even shellcheck can not help there. I have tried to solve the pitfalls in my library, but it turned out to be ugly and unreliable. That's why I'm trying to use rust [2] for shell scripting like tasks nowadays.

[1] https://github.com/anordal/shellharden/blob/master/how_to_do...

[2] https://github.com/rust-shell-script/rust_cmd_lib


Your [1] doesn’t mention it, but I find shopt -s inherit_errexit to be indispensable.

https://twitter.com/hellsmaddy/status/1273744824835796993?s=...


Unquoted argument is not an issue here, see some examples here: https://github.com/rust-shell-script/rust_cmd_lib/issues/10


since run_cmd! and run_fun! are returning result type, you can always do let _ = run_cmd!(ls nofile); to ignore single command error.

The “xxx || true” is for ignoring error within a group of commands, which is also very common in sh “set -e” mode. Without it, the group of commands need to be divided into at least 3 parts to still capture all possible command errors. I probably need to document this part with more details.


This ties in to what I wrote before: I prefer a philosophy where groups of commands are not written in the shell DSL, but are instead native statements (as much as possible), and the user is forced to use native control flow.

Documentation is not going to make me warm up to the idea, because I don't like having the choice to use the DSL so much.

With that in mind, perhaps I'm not the most valid person to provide criticism of this project ;)


Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: