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
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
I get why this is useful, and it’s useful for me as well, but the perfectionist in me asks why target bash instead of posix?
Currently, Amber does not even support Bash 2 because Bash 2 does not support the += operator. (ticket) However, I believe that POSIX compliance is on Amber’s long-term milestone, and that it will eventually achieve this as its support range expands.
my guess is mostly lack of arrays in posix shell. there are other things as well, but arrays are really useful, especially when they are making other things easier to write. A stupid comparison i can think of is a compiled language targettng x86-64v2 or 3 instead of v1 because it has avx (i am not actually sure when avx was added, but imagine some instruction being added). without avx, your binary would be slower (in posix, for arrays, you essentially need to maintain a string and use awk/sed/cut to get particular elements, and many things would just not be possible). If they would target v1 (posix), it will run in more places, but it would be slower for a lot of people who have v2 or newer. And a lot of people have v2 or newer (bash).
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?
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
shshell, 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.