4 ms·
I think the author forgets to mention that the primary reason bash is used is because of its cross distribution support. I known if i write my script in bash i
by rightisleft 9y ago
I think the author forgets to mention that the primary reason bash is used is because of its cross distribution support.
I known if i write my script in bash it will work on any small linux distro.
I think python is a close second, but it still use bash to bootstrap my environment for my real work.
- SwellJoe 9y agoI've been using POSIX shell exclusively, and spent a week or so converting all of my existing scripts to POSIX a few years ago (when Ubuntu switched its initscripts to run under dash instead of bash). Bash isn't available on tiny Linux distros by default, because it's quite large. Many use dash, including most busybox based distributions. With checkbashisms and shellcheck, it's pretty easy to spot compatibility issues and fix them.
- yjftsjthsd-h 9y agoAnd if you're POSIX compliant, you get to target every POSIX platform (GNU/Linux, BSDs, MacOS, GNU/NT) for free:)
- SwellJoe 9y agoIt's not quite free, in my experience, but yes, it is more cross-platform than bash. The price you still have to pay for cross-platform is the different paths, different output formats for system commands, etc. This is particularly pronounced for the stuff most of my lines of shell scripts are used for, where it's interacting almost entirely with system utilities to figure out where it's running and to do things to make sure the system is able to run the software my scripts are installing (which also interacts with the system in intimate and intrusive ways). But, you'd pay this with just about any programming language. Then again, I also use shell scripts for building/deploying things where a makefile would be overkill (and of course makefiles interact with the shell, too, so building your makefiles for POSIX shell rather than bash is also a good practice), and I make those with POSIX, as well. And, in those cases, it would definitely be OK on damned near any platform. I even worked on Windows for a few months when I got my current laptop because HiDPI support and the graphics drives on Linux just weren't working well enough, and most of my stuff worked fine there...both in the WSL and from a git bash prompt.
- jwilk 9y agoShouldn't busybox-based distros use busybox sh? (busybox sh is apparently a close cousin to dash, since they both derive from the Almquist shell.)
- SwellJoe 9y agoI dunno, I just read it when researching the state of shells on various distros. Yep, according to notes in the source for the busybox shell: "This shell is actually a derivative of the Debian "dash" shell by Herbert Xu, which was created by porting the "ash" shell, written by Kenneth Almquist, from NetBSD." https://git.busybox.net/busybox/tree/shell/Config.in?id=9d7010ca86feff8fffdfecadf6554ca9aac268c1 https://git.busybox.net/busybox/tree/shell/Config.in?id=9d70... So, yes, it is the "busybox shell", but the busybox shell is a version of dash. So, if you target dash, you're good for busybox distros.
- jwilk 9y agoPerl is probably better choice than Python for cross-distro support.