Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have just started learning the fundamentals of Unix and wondering why there are so many shells in a unix like system . From the book Advanced programing in Unix Environment:

A shell is a command-line interpreter that reads user input and executes commands.The user input to a shell is normally from the terminal (an interactive shell) or sometimes from a file (called a shell script).

And then the book goes on to list a number of shell programs like Bourne shell,Bourne-again shell,Cshell, etc . My question is basically why do we need multiple shells ?

share|improve this question
4  
The same reason that there are so many standards for various other technologies applies. xkcd.com/927 –  Dan Neely Nov 29 '12 at 13:24
1  
For the same reason why you can have compilers/interpreters for multiple programming languages (also multiple compilers for one language) or multiple internet browsers. –  Mischa Arefiev Nov 29 '12 at 13:59
5  
Your question is presumptious. "Why do we need multiple shells?" Who told you that we need multiple shells? Your book said we have multiple shells. That is not the same thing. –  Rob Nov 29 '12 at 20:27

5 Answers 5

up vote 13 down vote accepted

Most shells used in modern UNIX environments are meant to conform to the POSIX sh specification. POSIX sh is derived from the original Korn shell (ksh88), which is in turn derived from the earlier Bourne shell, but POSIX sh only specifies a small subset of even ksh88's functionality. A shell that only implements the minimum requirement is missing many features required for writing all but the most trivial of scripts in a safe and reasonable manner. For example, local variables and arrays are non-standard extras.

Therefore, the first reason is to extend the shell with extra features. Different shells choose to focus on different things. For example, Zsh focuses on advanced interactive features while ksh93 (the current "original" korn shell) focuses on powerful programming features and performance. Even very minimal shells like Dash add at least a few non-standard extras like local variables.

Extra features are rarely widely interoperable, if at all. Most of the ksh88 featureset is fairly well interoperable such as the extended globbing syntax, but with non-standard features, there are no guarantees, and you must really know what you're doing to use them in a portable way.

The second reason is legacy. There are still a lot of proprietary Unixes out there that use ancient non-standard implementations for their /bin/sh. Until recently, Solaris still used Bourne as their defuault and chose to maintain the Heirloom shell rather than upgrade to something modern. These systems usually come with different shells you can switch to, for instance by changing your PATH variable or altering shebangs within individual scripts.

So to summarize. There are multiple shells, often by default:

  • For extra features, especially for dealing with non-portable extras.
  • To handle legacy scripts which are often unmaintained.
  • size / performance. Embedded systems often require small shells like mksh or busybox sh.
  • Licensing reasons. AT&T ksh was proprietary software until around 2000 or so. This is largely what gave rise to all the ksh-like clones such as Zsh and Bash.
  • Other historical reasons. Though not very popular today, there have been radical attempts at redesigning the language, such as scsh and es. The process substitution feature of many shells originally comes from rc (with a bit different syntax), and brace expansion from csh. Different shells have different combinations of such features available, usually with some subtle or not so subtle differences.
share|improve this answer
2  
Note that although local is not POSIX or Unix, it is specified and required in the Linux standard (LSB) and the debian policy standard. Note that es is a follow-up on rc. –  Stéphane Chazelas Nov 29 '12 at 21:26
    
What is now mksh originated as the Public Domain Bourne Shell, which was also written due to licencing reasons. (These issues still remain – licencing and portability and size were the three factors that helped me to persuade Google to include mksh with Android.) –  mirabilos Feb 27 at 14:17

Different shells exist for the same reasons as different web browsers exist: everyone has a preference, and some shells have historical baggage or momentum. Each has different features and idiosyncrasies.

share|improve this answer

Mostly, history...

Bourne was developed as part of (the propriety) SysV Unix, while BSD used csh... Later, bash was developed as a open-source alternative to Bourne shell (and its improved versions, like ksh). A Bourne-like shell was adopted in the POSIX standard. ksh is compliant and bash can be compliant.

Shells like csh and tcsh is much easier to use interactively than the original Bourne shell (which lack command completion, etc) but are horrible for scripting...

In some environments, such as Unix-based embedded systems, scripting features, size and speed is more important than interactive features like command completion, and a different variant of the shells tend to be used.

For portable scripting, you should use a POSIX compliant Bourne-variant and avoid extensions.

share|improve this answer
2  
-1 for thinking that the world began at SysV. The Bourne shell was released in UNIX v7 in 1977, six years before SysV was released. –  Rob Nov 29 '12 at 20:20
    
@Rob, s/1977/1979/ –  Stéphane Chazelas Nov 29 '12 at 21:29
    
Fair enough... The *nix history is quite complicated... See en.wikipedia.org/wiki/File:Unix_history-simple.svg –  Gert van den Berg Nov 30 '12 at 8:04

Short Answer

Due to a weird licensing history, no single entity has developed Unix. It was a community process where both volunteers and corporations have participated. These entities didn't always share all their tools, so separate shells happened. By the time we realized how counter productive this is, it was too late to unify all the shells in use. Instead work has been done to ensure that all these shells would be (theoretically) compatible with one another.

The long answer is complex and tightly linked to the history of Unix itself. There's no way it will hold on a single answer on this page, but it's been widely (mis)documented. You will find more detailed and precise answers by looking around the web and books dealing with Unix history.

share|improve this answer

Because people have different needs and it's good to have alternatives fitting your needs in the given situation. A shell is just a tool on its own and should be replaceable by any other in my opinion. That's the power of Unix/Linux, opposed to what Microsoft Windows has chosen to be.

Similarly... Why are there so many text editors? Why people develop a new browser if there's already one? Why is there GNOME, KDE, Xfce, LXDE, E17, etc.?

share|improve this answer
11  
Precisely. One could ask "why so many window managers?" as well. A unix native might ask the opposite question: why only one CMD.EXE? Why is Windows so rigid and not customizable? –  Bruce Ediger Nov 29 '12 at 13:05
1  
@BruceEdiger What do you mean, just one cmd.exe? There are alternatives to it, if you want to use them. Even Microsoft themselves have PowerShell as an alternative. –  Malcolm Nov 29 '12 at 22:37
3  
Even COMMAND.COM in DOS was replaceable. However, you often got a very brittle system due to the assumptions of other applications (and other users). As a result, there are few successful alternatives to CMD.EXE. One is PowerShell, which has the inertia of Microsoft backing it. Another example is, strangely enough, bash due to decent support from the Cygwin community, not to mention the MinGW folks. As for Window Managers, Windows has only had one at a time, but there have been several over time as the Windows environment itself evolved. –  RBerteig Nov 30 '12 at 0:33
1  
Thank you, RBerteig: well written. –  Bruce Ediger Nov 30 '12 at 2:28
    
+1 for this answer. I think that's why we have so many different diversified UNIX flavors: AIX, HP-UX, Solaris, Tru64, IRIX, UnixWare, OS X, Linux, FreeBSD, NetBSD, OpenBSD, ..., you name it! –  tonga Feb 18 at 2:08

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.