Is the default shell for all OSs except for Windows
BSD users would very much disagree, as would embedded Linux users and others. In fact, this assumption is a very common cause of portability problems for free and open source software.
I'm as guilty as anyone of assuming every shell is bash but when I had to make my software compile and run tests on both Linux and FreeBSD straight out of the repository I discovered that targeting the POSIX shell was not as limiting as you might think. I have since made it a habit to avoid "bashisms" in most scripts; a good way to start with that is to learn what is and isn't a bashism using a handy list found at http://mywiki.wooledge.org/Bashism.
Agreed. Many/most of the shell scripts I've ever seen using 'bash' could be using the standard 'sh' instead; most need no changes at all, and the rest need just a few minor tweaks to eliminate non-POSIX-compliant behavior.
Since Debian and other distros now use the BSD-licensed `dash` as their default system shell (system, not user) I suspect they've become more motivated to reduce unnecessary bashisms in shell scripts. Debian's 'devscripts'[1] project includes a Perl script called 'checkbashisms'[2] which you can use to detect many of these common 'bashisms'.
For those of you running Ubuntu, you can install 'devscripts' with apt-get: sudo apt-get install devscripts
For those of you running FreeBSD, you can install 'devscripts' from the devel/devscripts port.
Give checkbashisms a look. You can install it on Debian and its derivatives with
sudo apt-get install devscripts
Edit: It's a bit hard to find a current checkbashisms version on the Web (the one on SourceForge is an abandoned fork of an older version), so I've uploaded a recent stable one to http://pastebin.com/Ncu6DRuM. If you're not on Debian and decide to keep it clone git://anonscm.debian.org/collab-maint/devscripts.git.
Even for OSX its kinda iffy as statements go. I think (been a while now) tcsh was the default for < 10.3, 10.3 was zsh and maybe 10.4, then it moved to /bin/bash as default shell.
I think it's safe to wash <= 10.3 at this point, it has less than 0.01% market share. Most stat gatherers have actually stopped tracking anything below 10.4 or 10.5.
Also, I didn't know that zsh was ever the default? I thought it switched from tcsh to bash around 10.3 or 10.4.
zsh was only in I think 10.4 or 10.3, hard to tell anymore as I don't have any ppc machines to install any old os's on any longer.
Just giving historical context, not trying to say anything about markeshare or anything. Apple seems really willing to change shells is basically all my post amounts to.
Comments
BSD users would very much disagree, as would embedded Linux users and others. In fact, this assumption is a very common cause of portability problems for free and open source software.
I'm as guilty as anyone of assuming every shell is bash but when I had to make my software compile and run tests on both Linux and FreeBSD straight out of the repository I discovered that targeting the POSIX shell was not as limiting as you might think. I have since made it a habit to avoid "bashisms" in most scripts; a good way to start with that is to learn what is and isn't a bashism using a handy list found at http://mywiki.wooledge.org/Bashism.
Agreed. Many/most of the shell scripts I've ever seen using 'bash' could be using the standard 'sh' instead; most need no changes at all, and the rest need just a few minor tweaks to eliminate non-POSIX-compliant behavior.
Since Debian and other distros now use the BSD-licensed `dash` as their default system shell (system, not user) I suspect they've become more motivated to reduce unnecessary bashisms in shell scripts. Debian's 'devscripts'[1] project includes a Perl script called 'checkbashisms'[2] which you can use to detect many of these common 'bashisms'.
For those of you running Ubuntu, you can install 'devscripts' with apt-get: sudo apt-get install devscripts
For those of you running FreeBSD, you can install 'devscripts' from the devel/devscripts port.
[1]: http://packages.qa.debian.org/d/devscripts.html
[2]: http://anonscm.debian.org/gitweb/?p=collab-maint/devscripts....
There's no FreeBSD port called "devscripts", perhaps you meant devel/checkbashisms
You're absolutely correct, the port is devel/checkbashisms. My mistake.
https://www.freshports.org/devel/checkbashisms/
I wish there was a linter to check shell scripts for non-POSIX syntax and command invocations.
I'm put off trying to really grok *sh scripting because the landscape seems a bit of a confusing mess.
Give checkbashisms a look. You can install it on Debian and its derivatives with
Edit: It's a bit hard to find a current checkbashisms version on the Web (the one on SourceForge is an abandoned fork of an older version), so I've uploaded a recent stable one to http://pastebin.com/Ncu6DRuM. If you're not on Debian and decide to keep it clone git://anonscm.debian.org/collab-maint/devscripts.git.Thank you - I'm checking it out.
I don't think it's true of anything but OSX and most desktop linux-en. Solaris, hp-ux, AIX use(d) ksh, QNX too I think.
Even for OSX its kinda iffy as statements go. I think (been a while now) tcsh was the default for < 10.3, 10.3 was zsh and maybe 10.4, then it moved to /bin/bash as default shell.
I think it's safe to wash <= 10.3 at this point, it has less than 0.01% market share. Most stat gatherers have actually stopped tracking anything below 10.4 or 10.5.
Also, I didn't know that zsh was ever the default? I thought it switched from tcsh to bash around 10.3 or 10.4.
So I have an old copy of Mac OS X for Unix Geeks here.
10.2 was tcsh, 10.3 was tcsh for user shells and /bin/sh for scripts.
I think 10.4 was the zsh experiment, then 10.5+ bash. We'll see how long bash lasts being a gpl shell.
zsh was only in I think 10.4 or 10.3, hard to tell anymore as I don't have any ppc machines to install any old os's on any longer.
Just giving historical context, not trying to say anything about markeshare or anything. Apple seems really willing to change shells is basically all my post amounts to.
It was zsh emulating csh. they messed up by not using the almquist shell like the other BSDs.
Even if not the default shell on BSD, is bash available (by default)?
By default, no. Installable, yes.
Installed in /bin/bash? No as well. Don't start portable scripts with #!/bin/bash.
It can be installed via ports or packages.