I’ve been struggling with a rather complex shell script, and it’s becoming apparent that Bash might not be the best choice for this particular task. While I usually gravitate towards statically typed languages like Go or Rust, I’ve noticed that many people recommend alternative languages such as Lua or Python for scripting tasks.

I’m curious to know your opinions and experiences with scripting languages for larger or more intricate shell scripts. Have you ever encountered a situation where Bash just didn’t cut it, and if so, which scripting languages did you turn to for a more effective solution? Are there any specific languages you found particularly suitable for debugging, testing, or handling complex logic in your shell scripts?

You are viewing a single thread.
View all comments
13 points

For years my go to (after Bash) was Python. However, in the last few years I’ve switched to Rust for any kind of shell command wrapper or CLI tool.

TL;DR I think Rust is best suited to more complex CLI work.

permalink
report
reply
5 points
*

Exact same story here. Bash -> Python -> Rust.

Generally speaking, people should settle on a compiled language if they can. They can iterate as fast as interpreted languages these days.

Edit: If you want to try something different in scripting, try the execline language. Its interpreter processes the script and exits immediately even before the script execution begins. Traditional shell interpreters (like bash) stay active till the entire script is finished. Execline achieves this by a clever chaining of Unix execs, forks and variable substitutions. This makes execline scripts lighter (useful in embedded systems), more secure and less error-prone than traditional scripts. The downside is that writing them will feel a bit weird - since the fundamental paradigm is different from regular shells. However, that will be a refreshing change if you’re someone who likes to experiment and try new things.

permalink
report
parent
reply
3 points

Yes, and Rust with incremental compilation is pretty fast to iterate as well, as long as you don’t use massive libraries/build-scripts etc.

permalink
report
parent
reply
2 points

Just curious have you tried Go for this? Go was recently approved at work and I have seen articles about Go for things like this and just wondering if it is worth it. I have been using ansible and chef but need to explore other options. I want to use Rust but I know the road blocks I will have to work through at work. So just wondering if you had any insights to Go over Rust

permalink
report
parent
reply
3 points

Not him, but I much more like the type-system of rust (e.g. enums).

permalink
report
parent
reply
3 points

It’s especially true when you want to parse some json/xml/whatever. Just describe your datastuctures with regular struct and enum, add serde and done! It’s like magic!

permalink
report
parent
reply
2 points

I personally don’t have any real experience with Go. Lots of smart folks I work with love it. In general, most of what I have read suggests that Rust is better suited to CLI tooling. For my use case it came down to:

  • Rust’s cargo system
  • The clap crate (which supports building out bash shell completion scrips via a Rust build script. Basically means I can generate a completion script at compile time and include this in the package I distribute to users)
  • Rust’s out of the box performance
  • The heavy lifting done by the borrow checker in bringing safety
permalink
report
parent
reply
2 points

Would you have any example (not necessarily yours) to showcase this? I mean, how is it better suited than say, C++?

permalink
report
parent
reply
8 points

Not op, but I feel the same as them.

Compared to C++, Rust has a very good toolchain and libraries. With C++ setting up a project that has dependencies is… painful. I’m a full-time C++ programmer with over 8 years of experience and if I didn’t have to, I would never choose it for something new.

With Rust creating a new project and adding dependencies is trivial. There are a lot of great libraries and the ease with which you can use them is very empowering.
Clap and serde are super powers for CLI programs 😀

For smaller scripts that don’t yet “deserve” full rust treatment, I now use nushell for personal projects.

permalink
report
parent
reply
4 points

I too use Rust for what normal people use shell scripts for. But I have a feeling that Rust is falling into the same trap that other languages with similar easy dependency management fall into (Python and NPM are good examples). You end up with a dozen direct dependencies and hundreds of indirect ones with dozens of levels of hierarchy. C and C++ programs have fewer dependencies because each additional one adds more headache for the developer. Drew Devault’s Hare language is giving language repo and package manager a skip for the same reasons. And I’m starting to think that he may have a point.

permalink
report
parent
reply
1 point

I personally don’t have any real experience with Go. Lots of smart folks I work with love it. In general, most of what I have read suggests that Rust is better suited to CLI tooling. For my use case it came down to:

  • Rust’s cargo system
  • The clap crate (which supports building out bash shell completion scrips via a Rust build script). Basically means I can generate a completion script at compile time and include this in the package I distribute to users)
  • Rust’s out of the box performance
  • The heavy lifting done by the borrow checker in bringing safety
permalink
report
parent
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 1

    Monthly active users

  • 555

    Posts

  • 2.8K

    Comments