SEARCH

How-To Geek

HTG Explains: What Are the Differences Between Linux Shells?

banner-01

We’ve been covering topics on shell scripting because Linux can be put on almost anything. The versatility of the command-line shell is what really allows this, but what makes each shell different and why do people prefer one over another?

What Do Shells Do?

The  command-line is a very interesting thing. Once considered to be the most advanced user interface, it has gone the way of waistcoats and fountain pens: shunned to the periphery. While you still see much of the purpose and utility in them, they’re usually left aside primarily for enthusiasts to appreciate, mainly because they spend the time to learn the ins and outs of them. Indeed, the command-line in any given operating system will have a lot of quirks because easy OS interprets commands differently. Today, this is mainly an issue between Linux, OS X, and Windows, but before this was a problem with most computers.

blakespot2376243022_eb9edb1c77_z

(Image by blakespot)

Shells entered the picture and allowed a more standard extension of the command-line in a way that was much more inconspicuous. Shells added a lot of functionality, such as command and file name completion and more advanced scripting abilities, and helped bring some performance enhancements. They also did a lot to cover some annoying problems. For example, in Unix, you couldn’t back up through symlinks to the directories before you followed them. All in all, they added some features that allowed users to get their jobs done more quickly and efficiently, just like Linux’s plethora of alternative Window Managers.

Why Are There So Many?

sshot-4

The most prominent progenitor of modern shells is the Bourne shell – known as ‘sh’ – which was named after its creator Stephen Bourne who worked at AT&T. It became the default Unix command-interpreter because of its support for  command substitution, piping, variables, condition-testing, and looping, along with other features. This was in an era that programming really went along with using the command-line, a practice that many argue has been diluted today. It did not offer users much leeway in customizations for users, such as aliases, command completion and shell functions (though this last one was eventually added).

C shell (‘csh’) was developed Bill Joy at UCB and really shook things up. It added a lot of interactive elements that users could use to control their systems, like aliases (shortcuts for long commands), job management abilities, command history, and more. It was modeled off of the C programming language, an interesting idea because Unix was written in C. It also meant that users of the Bourne shell had to learn C so they could enter commands in it. In addition, it had tons of bugs which had to be hammered out by users and creators alike over a large period of time. People ended up using the Bourne shell for scripts because it handled non-interactive commands better, but stuck with the C shell for normal use.

Over time, lots of people fixed the bugs in and added features to the C shell, culminating in something called ‘tcsh’. The problem, then, was that in distributed Unix-based computers, csh was still the default, and had some added “non-standard” features added in, creating a very fragmented mess of things (in retrospect). Then, David Korn from AT&T worked on the Korn shell – ‘ksh’ – which tried to mitigate the situation by using the Bourne shell’s language as a basis, but added in all of the new features that everyone was accustomed to. Unfortunately for many, it wasn’t free.

sshot-1

Another response to the hectic proprietary csh implementations was the Portable Operating System Interface for Unix, or POSIX. It was a successful attempt at creating a standard for command interpretation (among other things) and eventually mirrored a lot of the features that the Korn shell had. Simultaneously, the GNU project was going on and was an attempt at creating a free operating system that was completely Unix-compatible. It developed a shell for its own purpose: the Bourne Again shell, formed by bashing together features from sh, csh, and ksh. The result, as seen in retrospect, was pretty impressive.

Kenneth Almquist created a Bourne shell clone – ‘ash’ – that was POSIX-compatible and would become the default shell in BSD, a different branch/clone of Unix. Its uniqueness is that it’s really lightweight, so it became extremely popular in embedded-Linux systems. If you have a rooted Android phone that has BusyBox installed, it’s using code from ash. Debian developed a clone based on ash called ‘dash’.

othree4240326365_3ca467f0c9_o

(Image by othree)

One of the most prominent of “new” shells is ‘zsh’, developed by Paul Falstad in 1990. It’s a Bourne-style shell that takes features from bash and previous shells and adds even more features. It has spell-checking, the ability to watch for logins/logouts, some built-in programming features like bytecode, support for scientific notation in syntax, allows for floating-point arithmetic, and then some. Another is the Friendly Interactive Shell, ‘fish’, which focuses on command syntax that’s easy to remember and use.

On the whole, most shells were created as clones of previous shells that added functionality, fixed bugs, and bypassed licensing issues and fees. The notable exceptions are the original Bourne shell and the C shell, and both rc shell and ash which aren’t entirely original but definitely have some niche-utility.

Which Should I Use?

sshot-2

With so many out and about, you’d think that it’s hard to choose which shell to use, but it’s actually not very difficult. Since so many are based off of Bourne shell, basic things will be the same between most shells.

Bash is the most widely used shell out there and is the default for most Linux distributions. It’s really robust and has tons of features, most of which you probably won’t use unless you program, so it’s pretty safe to say you can stick to this one. Because it’s so common, it’s perfect for scripting things that will be used across different platforms. If you want to try something different that’s a little more user-friendly, you can try out fish instead.

If you tinker with embedded-Linux systems a lot, like to put Linux on ridiculous things like your Nintendo DS, or you really like Debian, then ash/dash is probably best suited for you. Again, it works mostly like the others, but since it’s sort of bare-bones and light-weight, you’ll find some more complicated functionality missing.

renrutal135123038_5d960b60c3_z

(Image by renrutal)

If you plan on programming or learning to develop on the command-line, then you’ll have to be a little more choosy. Bash is a fine choice, but I know enough people who have switched to Zsh for its extras. I guess it really depends on how complicated your projects will get and what type of functionality you prefer from your shell. Some people still stick to tcsh because they know and use C regularly and it’s easier for them. Odds are that if you’re not sure which shell to choose, you probably don’t program much, so try to choose something that will line up with what you want to learn and do some research on what others in that field use.

You can easily install and remove different shells using the Software Center on Ubuntu or your preferred package manager. Shells are located in the /bin/ directory, and as long as you’re running a modern Linux distribution, it’s easy to change what your default is. Just enter the following command:

chsh

You’ll be prompted for your password, then you can change to a different shell by entering its path.

sshot-9

In square brackets, you’ll see your current default, and if you want to leave it as-is, just hit Enter.


Do you stick to bash? Do you have another favorite shell? What’s your most-used feature? Tell us your thoughts in the comments!

 

Yatri Trivedi is a monk-like geek. When he's not overdosing on meditation and geek news of all kinds, he's hacking and tweaking something, often while mumbling in 4 or 5 other languages.

  • Published 07/22/11

Comments (11)

  1. Tim Cuthbertson

    I stick with bash in Linux, but when I worked on Solaris systems, I always changed from Bourne shell (sh) to Korn shell (ksh). I have dabbled with zsh and ksh93, but I always seem to fall back to bash or ksh.

  2. Chilenoneto

    There is a huge list of reasons to say that bash is by far the most common linux shell, to metion some of them:
    - Its default in 99% of normal user popular distributions (Ubuntu, Fedora, and so on)
    - Its pretty simple to use as a begginer, and powerful enough to most advanced tasks
    - 99.99999% of command lines samples on support forums are formatted using bash sintax.

    But there are some improvements to make it easier to use and get hands on it, like Install popup hotkeyed support: on gnome guake, on kde yakuake… press f12 and it will show top to bottom with a scrollable popup (Quake alike, hence the names)

    There is to mention too the everyday growing, and getting more powerful on every update, windows powershell, available to download and install for free from microsoft.

    With it you can access great scripting and task enhanced features. worth a look!

  3. Trevor Bekolay

    Great article Yatri! Personally, I use Zsh on both my Linux machine and my Macbook.

  4. Chilenoneto

    Update … Windows 7 (at least ultimate) has Powershell buitin !! windows+r, type powershell and hit enter and presto!

  5. rushfan54

    I script in bash but do everything else in fish.

  6. herbie643

    What the powershell is missing is History. Go to powershell, type in a bunch of commands. Exit out, go back to Powershell and no command history. Microsoft should really implement a history function, built-in, nothing you have add or trigger.

  7. fengshaun

    I use zsh for the following reasons:

    - great vim-style keybindings for line editing
    - nice history features
    - the prompt is easily customized (with right-aligned prompt)
    - bash scripts work just fine in it, nothing too radical!
    - who could forget awesome completion?
    - recursive directory listing and super-nice filters (rm **/*.py{c,o} comes to mind :) )

  8. Litho

    Mostly Zsh for me these days.

  9. Eric

    I use Bash, but mostly because all of the scripts I’ve already written (or obtained, in some cases) are written in Bash. I’m also pretty sure that’s almost everyone else’s reason.

  10. brumm

    bash! Nothing else………………………

  11. kinudig

    @chilenonoeto: I have Win7 Home Premium and powershell is available too. Neat! Now I just need to figure out what I can do with it…

Get Free Articles in Your Inbox!

Join 134,000 newsletter readers

Email:

Go check your email!