News for hackers. Stuff that matters.

rustshellscript

Re:Was Rust Worth It? on Thursday October 26, 2023 @03:10AM (#38022631)
Re:Was Rust Worth It? on Thursday October 26, 2023 @03:06AM (#38022616)
Re:Bash functions are better than I thought on Monday November 01, 2021 @08:04AM (#29065625)
Here is the rust library with the “the only good parts” of bash/shell script: https://github.com/rust-shell-script/rust_cmd_lib
Re:What was the point of [ “x$var” = “xval” ]? on Monday April 12, 2021 @05:33AM (#26777492)
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 ?

Re:How to do things safely in Bash (2018) on Saturday April 03, 2021 @02:41PM (#26683536)
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
Re:Minimal safe Bash script template on Tuesday December 15, 2020 @10:50AM (#25431342)
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.
Re:Futures explained in 200 lines of Rust on Thursday December 03, 2020 @05:38PM (#25296266)
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" :)
Re:Bash Pitfalls on Monday September 07, 2020 @06:44PM (#24403571)
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

Re:Show HN: Using Rust to write shell-script like tasks on Sunday August 23, 2020 @12:12PM (#24252873)
Unquoted argument is not an issue here, see some examples here: https://github.com/rust-shell-script/rust_cmd_lib/issues/10
Re:Show HN: Using Rust to write shell-script like tasks on Sunday August 23, 2020 @12:06PM (#24252822)
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.

Re:Show HN: Using Rust to write shell-script like tasks on Sunday August 23, 2020 @10:06AM (#24252040)
It can be supported with internal APIs, even without macros: Cmds::from_cmd(Cmd(...).current_dir(..)) .pipe(Cmd(...).current_dir(...)) .run_cmd(...)

As you can see, it is very verbose and that's why I choose to hide the lower APIs at this moment.

Re:Show HN: Using Rust to write shell-script like tasks on Sunday August 23, 2020 @08:50AM (#24251537)
Thanks, yes since I just finished the core functionality of this project and I am not surprised if it is still missing some critical features when converting bash script. Pls file bugs if you find anything :)
Re:Show HN: Using Rust to write shell-script like tasks on Sunday August 23, 2020 @08:43AM (#24251502)
You can consider it was enabled by default, and any failed command would return error unless you mask it with “xx || true”.
Re:Show HN: Using Rust to write shell-script like tasks on Sunday August 23, 2020 @08:40AM (#24251481)
Yes, I also use this for automatically capturing command error messages with timestamps into logs: https://github.com/rust-shell-script/bash_cmd_lib/blob/0b0a6...

However this can be fragile in bash script since any sub shell command can fail. I am still wandering how to support it in this rust_cmd_lib library.

Re:Show HN: Using Rust to write shell-script like tasks on Sunday August 23, 2020 @08:22AM (#24251372)
Author here, thanks for your feedback. This library is calling std::process::command underneath without any shell dependency, which I believe is the same as plumbum’s run* APIs and I should make it clearer in the docs.

This plumbum has its own “cp”, “cat” .., which is similar to shelljs and it looks like a lot of people like this idea which can also be supported by this library in the future.

Re:Crafting Interpreters: Closures on Friday September 27, 2019 @01:38PM (#21094323)
I am recently working on a hobby programming language: https://github.com/rust-shell-script/rust-shell-script, which could compile to either rust code or shell script. This book helps me clarified a lot of things along the implementation.