Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My problem with other bash alternatives like zsh or fish is that it develops habits that don’t translate across servers that might only have bash.

I prefer using bash in this case because it means my bash scripts are more portable across different systems.



I use zsh, and any scripts I make just use plain sh.


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.


I 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.


No, 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


Is it a lot of mental effort to keep in mind which commands are zsh compatible only and which are plain sh?


I tend to check every script I write using shellcheck[0]. This will detect if a script starts with `#!/usr/bin/env sh` but uses bash or zsh features. Never had a problem an never thought much about it.

[0]: https://github.com/koalaman/shellcheck/


I don't recall ever running into something that didn't work in plain sh. I have never scripted in zsh. I'm probably missing out on some advanced features, I guess.


I do use zsh, but I could care less for the fancy features, which I mostly ignore.

In fact my shell dotfiles are mostly compatible with both, and when they’re not I managed to backport the interesting bits to bash.

TBH I use zsh only because it’s the default in macOS, where bash is both ancient and deprecated.

But zsh is not “simple enough”. The gajillion features are just dead weight and needless complexity to me.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: