3 ms·
I think this is key. In my dot files, I take advantage of all the zsh features if I need to. But when I write a script that's meant to be executed rather than
by dastx 6y ago
I think this is key. In my dot files, I take advantage of all the zsh features if I need to.
But when I write a script that's meant to be executed rather than sourced, I aim to use posix wherever possible, and fall back to bash if it's not.
- signal11 6y agoI wonder if POSIX/sh is really necessary if you're targeting Linux. I mean, if you're targeting multiple Unixes, sure, but a lot of my scripts are company/infrastructure specific and won't really target anything but Linux and bash is always available. Even if we used a BSD for something tomorrow, it'd be trivial to add bash to those. I may be missing something, however. I guess the one place I can think of is some small-container scenarios, e.g. a bash-less Alpine, where you want the smallest possible image.
- dastx 6y agoNo, I don't think POSIX is as necessary as many people make it out to be, because it really depends on your use case. I've always been able to rely on bash both professionally and in my own projects. I am however aware of people who have to rely on posix compatibility. One of them is as you said, docker environments and alpine Linux, the other is a former colleague was working on some airgapped system where security didn't allow any additional packages to be installed, and bash wasn't installed. So their only way of scripting was either posix, or an old version of python 2 (I think it was 2.3). I don't know whose brilliant idea it was to install python, but not bash. So it really depends on your use case