4 ms·
The biggest benefit to Bash scripting over a friendlier language is that Bash is guaranteed to just work on pretty much every machine. Bash is on virtually ever
by oxguy3 8y ago
The biggest benefit to Bash scripting over a friendlier language is that Bash is guaranteed to just work on pretty much every machine. Bash is on virtually every *nix machine (except maybe embedded devices), and it's extremely resilient to time. Looking through the change history (https://wiki.bash-hackers.org/scripting/bashchanges https://wiki.bash-hackers.org/scripting/bashchanges), I'd wager that 99% of scripts don't use anything that wasn't in Bash 2.05b, which came out in Jul 2002. Anecdotally, the "newest" feature that I've ever used is regex support in conditional expressions, which was added in 3.0-alpha (Aug 2004).
Ruby and Python, meanwhile, are not quite so universally installed as Bash, and they have had all sorts of major breaking changes since 2004. And even if they are installed and version-compatible, they still might not work. Countless times have I seen a misconfiguration with Python 2 vs 3 or RVM or the PATH variable or whatever else cause errors, but I have never run into a scenario where a Bash script didn't just work.
All that said, I'm totally with you that Bash scripts should be short and sweet. If you're doing something with over 100 lines, Bash's downsides overtake its benefits.
- roryrjb 8y agoIt's true that bash can be installed on any Unix-like OS, but so can Python, Perl, etc, but it's not available by default, on OpenBSD there's pdksh, FreeBSD tcsh iirc, and on MacOS I believe the version of bash is really old due to some previous license change. Edit: I read your post quickly, you addressed the old bash scenario, but still in my opinion I would always, and do target POSIX shell for maximum cross-platform compatibility and that is definitely available on Unix-like OSs by default.
- ricardobeat 8y agoThat’s true, and it’s the reason the tools I mentioned were written in Bash in the first place. Python 2/3 was a pain, Ruby had very disparate versions available. But now, a few years later, you can assume at least Ruby 1.9 nearly everywhere, and OTOH still can’t use any of the Bash 4 features. There also quite decent cross-platform packaging solutions for python, ruby, node, go, crystal, mruby that make it really hard to choose bash for any serious project.
- oweiler 8y agoWhile Bash itself is portable, the commands Bash scripts glue together are often not.