Better Scripts #2 - Don’t use bash

If you want to cause a controversy on mailing lists go ahead and ask a question about which shell you should use. There are a million different opinions about this even though there is not that many shells available.

However, when you want to write portable scripts please don’t use bash but use ksh (or even better sh). bash is not installed by default on all platforms but ksh and sh exists almost everywhere. If you are used to Linux most distributions sh is usually a symlink to bash. E.g ubuntu has broken with this tradition and sh is no longer bash. Recently I have had a couple of problems with scripts on ubuntu and they have all been solved by changing the first line from sh to bash.

If you want a script in bash please make sure you specify bash on the first line. But if you want make it portable use ksh and sh and make sure you only use features that are available in those shells.

[?]
Do you need system administration assistance? If you like what you are reading please consider subscribing to the RSS feed. If you have feedback or if you find the article useful please leave a comment below.

Leave a Reply