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?

  • Prosperoh@jlai.lu
    ·
    8 months ago

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

    • miniu@programming.dev
      cake
      ·
      8 months ago

      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.

      • TechNom (nobody)@programming.dev
        ·
        8 months ago

        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.

        • philm@programming.dev
          ·
          edit-2
          8 months ago

          I think it's not that bad yet, when comparing with npm. Usually the dependencies I use are of very high quality. But I'm also very selective with dependencies. I'm rather writing a simple part myself, than using a not-really maintained low-quality dependency...

          Btw. I have not looked into the Hare language yet (will do that now), but if it's similar as deno, I won't like it. You want to have some kind of package management IME...

          • philm@programming.dev
            ·
            8 months ago

            Drew Devault’s Hare language

            Ok, they say "use your distros package-manager", that's basically asking for the same disaster as C or C++. I think cargo is one of the selling points of Rust.

            At least say something like we use "Nix" for default package-management (which does a lot of things right)...

    • lxkota@lemmy.ml
      ·
      8 months ago

      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