My primary use case for Amber is when I need to write a Bash script but don’t remember the silly syntax. My most recent Bash mistake was misusing test -n and test -z. In Amber, I can just use something == "" or len(something) == 0

  • Jakeroxs@sh.itjust.works
    link
    fedilink
    arrow-up
    1
    ·
    13 hours ago

    As someone who knows nothing about POSIX, what’s the difference or in your opinion what would make it specifically better with the context of amber?

    • confusedpuppy@lemmy.dbzer0.com
      link
      fedilink
      arrow-up
      1
      ·
      9 hours ago

      I’ve been writing POSIX scripts as a sort of hobby and don’t really have any Bash experience but I think I can still give some insight. Hopefully what I say is accurate but this is what I’ve learned so far.

      POSIX is a standard, to say it as simple as possible, it sets the minimum requirements for environment, programs, commands and options for those commands with the purpose of having those commands be as portable as possible. That way a POSIX script will work on any POSIX compliant system. For example a POSIX script could work on Arch, Debian, on a Raspberry Pi or even Mac products. In theory if could work on windows too. If an Operating System ships with a POSIX compliant shell, you are very likely able to run a POSIX script.

      Bash is a shell but it has a bunch of features that expand beyond the basic features set by the POSIX standard. Bash also has more features and flexibility for scripting which is why it’s so common to see Bash scripts. Those scripting features are usually referred to as “bashisms.” Since it expands on POSIX scripting, it can look similar to a POSIX script but would not work as intended if you ran a Bash script outside of a Bash shell.

      With a lot of modern OS’s, they would likely have Bash installed and you most likely don’t need to worry about anything. However, Bash is not a standard and not required to be installed on every system.

      If you care about your script working on as many systems as possible without the worry about what shell is being used, you will probably prefer writing a sh shell, POSIX compliant script.

      Since POSIX shells and scripts work on a much more basic level, it can lack some depth and finding work arounds for issues can start to look unreadable/insane. A good example is how arrays are handled. POSIX is limited to one array where Bash has much better support for arrays.

      There are advantages to using either but with the popularity of Bash, it’s not really that big of a deal in the end.