In short, Amber is a programming language with Rust like syntax that compiles down to bash. More details here: https://amber-lang.com/

On the surface, it seems nice. Cleaner syntax, types, compile-time safety checks, etc. So you get to write in something nicer than bash but get the portability of bash.

My wonder is if there are pitfalls that make it worse than instead writing it in something like Python or even bash itself. I’d guess the generated bash code probably isn’t the prettiest to look at or debug.

    • Let’s also remind that at least Helix the very good editor automatically runs bash stuff through Shellcheck if you have it installed, while you type. It’s been amazingly useful and educational. I write a lot of bash at work and have learned many finer details from Shellcheck’s hints.

      It even does the Clippy thing. I’m piping something into a sed s/…/… and it tips ‘try ${variable//search/replace} instead’.

    • They mention in the FAQ that they currently require some features of Bash but are thinking about including POSIX sh as a possible target. My guess without investigating is that they are using a thing like arrays that make implementation way easier but is not technically POSOX sh.

    • Quibblekrust ( Quibblekrust@thelemmy.club ) 
      link
      fedilink
      English
      arrow-up
      17
      ·
      4 months ago

      It’s not Rust, OP was mistaken. It’s ECMA-Script-like with Rust-like features and also Python-like features.

      I think the idea is, you can develop Amber scripts “at home” then deploy them on any machine that has Bash without needing to install anything. This benefits system admins.

      Amber compiles directly to shell code, so you can:

      • Leverage existing shell tooling and pipelines.
      • Deploy a single script without installing a language interpreter.
      • Benefit from shell‑native features (process substitution, job control) while enjoying high‑level syntax and safety.

      Is Amber production‑ready?

      In the the project it is production ready because it is already used in this context because the shell code generated is tested and confirmed that works, the language is evolving with the tooling set.

      Well, their FAQ isn’t exactly production ready.

  • IanTwenty ( IanTwenty@piefed.social ) 
    link
    fedilink
    English
    arrow-up
    8
    ·
    4 months ago

    I like the idea as BASH is available everywhere but has terrible gotchas in its syntax plus at times is unreadable.

    When I did some moderately complicated amber scripts I hit bugs. Also still some important features are missing.

    So I’m keeping an eye on it but it’s definately not ready for anything serious yet.

    I am also watching https://oils.pub/ and hoping one or both of these projects succeed.

  • If you just want portability, then this could be useful. However, in my opinion a large part of why I use a shell script is to avoid compilation and just hack something together. If your goal is shell scripts that are easier to write you could also check out other shells:

    • fish is the easiest to use in my opinion, but is not POSIX compliant so you do have to learn the syntax.
    • zsh is a nice quality-of-life upgrade over BASH, tweaking the little things
    • There are also things like xonsh which use Python syntax for shell scripting, but I dont have personal experience with them.
  • jokro ( jokro@feddit.org ) 
    link
    fedilink
    arrow-up
    1
    ·
    4 months ago

    This is nice. Writing safe bash scripts includes avoiding implicit pitfalls. If the tool actively stops you from that it’s great. I wished this would have existed some years back.

  • liliumstar ( liliumstar@lemmy.dbzer0.com ) 
    link
    fedilink
    English
    arrow-up
    1
    ·
    4 months ago

    I have used it, and honestly it’s better than writing pure bash. But it’s not perfect. Still needs a lot of work, and there are a bunch of weird limitations and things you need to remember. So I would say it’s main use case is where you absolutely need bash portability over a more robust scripting/programming language.