Difference Between Bash, sh and other Linux Shells

Linux consist of many shell environments and these can be used interchangeably. Bash (Bourne-Again SHell) is a particularly popular shell.

The key question to think here is what’s the difference between these, and foremost, why does there exist so many environments?

What does a Shell do?

Shell is an interface between a user and OS to access to an operating system’s services. It can be either GUI or CLI (Command Line interface).

To summarise, let’s quickly lay down what a shell is:

  • It is a program that runs in the terminal
  • Shell is both a command interpreter and a programming language
  • Shell is simply a macro processor that executes commands.
  • Macro processor means functionality where text and symbols are expanded to create larger expressions.

The shell is also used in the background by various system services. Linux distributions include many functions written as shell scripts. These scripts are commands and other advanced shell scripting functions run through the shell environment.

Difference

There exist many shell environments like bash, sh (Bourne Shell), csh, ksh (Korn shell), tcsh, zsh. Let us learn briefly about each of these:

  • sh : If a script is intended to be run on any Unix system, then it will be written in sh. It is more compatible with other (and older) Unix systems and it is the standard default shell for non root users in FreeBSD.
  • bash : The Bourne Again SHell started as an sh-compatible implementation, but as time passed it has acquired many extensions. It is a command interpreter and a programming language
  • csh : The C shell, or “csh” added a lot of interactive elements with which users could control their systems, like shortcuts for long commands, job management abilities, command history.
  • tcsh : tcsh shell was actually just an extension of csh shell in which lots of bugs and issues were fixed.
  • ksh  : Korn Shell (ksh) is backwards compatible, and is also free in the form of clones (mksh) and the recently released original (ksh). Uses abbreviation ksh or ksh93.

How was Bash born?

All of the shells except bash came before it. The Bourne-Again Shell, or Bash, is an open source GNU project intended to replace the Bourne shell.

In addition to supporting backward-compatibility for scripting, Bash has incorporated features from the Korn and C shells. You’ll find command history, command-line editing, a directory stack (pushd and popd), many useful environment variables, command completion, and more.

Bash has been improved in the decades since its first release in 1989, but it’s still the default shell on most Linux distributions today. It’s also the default shell on Apple’s macOS.

Miguel

I started this tech blog back in 2011 as a place to write down processes I took to fix my client systems and network. Now I write some tips and tricks to help others with the tech issues that one might encounter.

You may also like...