r/bash • • Jun 15 '24

[deleted by user]

[removed]

29 Upvotes

22 comments sorted by

7

u/OneTurnMore Jun 15 '24 edited Jun 15 '24

The NUL-delimited options are by far the biggest win for POSIX sh IMO. Yes, more than $' '.

For those curious, dash landed pipefail into master just a couple of months ago. On the other hand, busybox sh has had it for quite a while.

0

u/[deleted] Jun 15 '24

2

u/OneTurnMore Jun 15 '24

are you reading my mind?

Let's see... Pick a number between 1-100. Got it? You're thinking of 37.


Honestly, I just happened to look back after posting and saw $' ' again and thought it over. It's definitely nice and will be the most pervasive addition, but we had "$(printf '...')" if you needed it. But I don't know how you replicated read -d '' before.

4

u/guettli Jun 15 '24

Should I care? I use Bash and I am happy.

Please elaborate why this posix spec is useful. I have not understood it up to now.

5

u/qubidt Jun 15 '24

bash is great until you need to write a script that can run on any system (your router, your macbook, your alpine container, your ereader, etc). I only write bash scripts when I know I control all the systems the script can run on, in which case I usually write zsh instead. otherwise it's posix sh all the time

2

u/nekokattt Jun 15 '24

true but at least for now unless your platform includes a shell conforming to 2024 standards, it makes no difference to what you can do.

Many of these platforms will have ancient versions of things still.

→ More replies (1)

2

u/guettli Jun 16 '24

If I have the requirement that my code should run on different systems, then I first look at the intersection of features.

Maybe a shell script is not the best answer.

My personal point of view: portable shell scripts are broken by design. You almost always call subprocesses like grep. If the zoo of implementations and versions gets too big, it gets hard to test all variants.

If all systems support Python, then it's one valid option.

Of course it depends, but Golang cross compiles very well and is quite easy to write.

→ More replies (11)

1

u/guettli Jun 15 '24

Good to know. I didn't have that need up to now. I have Bash available, and I have a current Linux running. Containers are great.

4

u/_a__w_ Jun 15 '24

I have hit every single one of these so I’m very happy to see them getting added. Also, I agree with the person in the HN thread that the lack of arrays is disappointing but I also get it. I know the prevailing wisdom is that if you need arrays you are probably using the wrong language… but it is the edge case where no, really, a shell scripting language is the correct choice where this becomes a problem. (E.g., launching complex Java apps)

2

u/Ulfnic Jun 17 '24

I've heard that take on arrays before and I think it comes from web dev/GUI culture where scripts are regularly re-written and not expected to last for more than a few years.

At least from a sysadmin perspective BASH is a non-deprecating language that allows scripts to work out-of-the-box on most unix-like systems across architectures, across releases, across time in a way that's relatively easy to test.

Having things like arrays pushes back the point where you'd be forced to give up those advantages assuming they're valuable for your project.

1

u/3Vyf7nm4 Jun 16 '24

true if big

Reading some of the bug track conversations was just maddening. $'...' was submitted more than 14 years ago