Text-only Table of Contents (frame/ no frame)
(6) ksh/bash vs sh Previous Top Next

ksh/bash vs sh

Ksh and bash are both supersets of sh. For maximum portability, even to very old computers, you should stick to the commands found in sh. Where possible, ksh or bash-specific features will be noted in the following pages. In general, the newer shells run a little faster and scripts are often more readable because logic can be expressed more cleanly user the newer syntax. Many commands and conditional tests are now internal. Less detail
The philosophy of separate Unix tools each performing a single operation was followed closely by the designers of the original shell, so it had very few internal commands and used external tools for very trivial operations (like echo and [). Ksh and bash internally performs many of the basic string and numeric manipulations and conditional tests. Occasional problems arise because the internal versions of some commands like echo are not fully compatible with the external utility they replaced.

The action taken every time a shell needs to run an external program is to locate the program (via $PATH), fork(), which creates a second copy of the shell, adjust the standard input/output for the external program, and exec(), which replaces the second shell with the external program. This process is computationally expensive (relatively), so when the script does something trivial many times over in a loop, it saves a lot of time if the function is handled internally.

If you follow textbooks on Bourne shell programming, all of the advice should apply no matter which of the Bourne-derived shells you use. Unfortunately, many vendors have added features over the years and achieving complete portability can be a challenge. Explicitly writing for ksh (or bash) and insisting on that shell being installed, can often be simpler.

The sh and ksh man pages use the term special command for the internal commands - handled by the shell itself.

Previous Top Next

ksh-vs-sh.src  last modified Mar 10, 2005 Introduction Table of Contents
(frame/no frame)
(single file)
© Dartmouth College