A shell in Rust could be really cool
A shell in Rust could be really cool
Posted Feb 12, 2025 21:20 UTC (Wed) by walters (subscriber, #7396)In reply to: A shell in Rust could be really cool by koverstreet
Parent article: Rewriting essential Linux packages in Rust
But on the topic of scripts and testing - in bootc I started to try to use nushell for some of our integration tests which are *mostly* just forking external processes, but have about 10% where you really want things like arrays.
You can get a good sense of what this is like from e.g. this test:
https://github.com/containers/bootc/blob/main/tests/boote...
A notable plus is that it's super easy to parse JSON from a subprocess without falling back to jq and thinking about its mini-language and then parsing that back into bash.
But a downside is we've been caught twice by subtle incompatible nushell changes:
- https://github.com/containers/bootc/pull/911/commits/6f80...
- https://github.com/containers/bootc/pull/937/commits/28e8...
I hope this won't happen too much more often...
---
If you want to approach this a different way and write a regular Rust program but fork subprocesses with as little ceremony and overhead as possible, I heartily recommend https://crates.io/crates/xshell
It's really cool because it makes use of Rust macros to do what you can't easily do in Go or Python - correctly quote subprocess arguments referring to Rust local variables.
