michelangelus - Fotolia


A look at the main differences of Bourne shell vs. Bash

Shells help admins run commands from the keyboard to the OS. Though Bourne shell and Bash are similar, there are differences in layout and code compatibility.

Most Linux admins are hard-pressed to avoid the terminal window. It's almost as though it's in your blood to automatically use commands. And when you do, you usually work with Bourne Again Shell, also known as Bash.

But what is a shell? It is a program that accepts input from a keyboard and hands it off to the OS. As you type commands, the shell interprets them such that the OS can understand them.

Bash's syntax is a superset of Bourne. Since its original release on June 8, 1989, Bash has become the de facto shell for the Linux OS.

Of course, there are numerous shells available for Linux. In addition to Bash and Bourne shell, there are Korn, C, tcsh and Zsh. But the most widely used is Bash.

Overall, it's a rare instance to come across a true Bourne shell. If you use FreeBSD or Unix, you will most likely work with Bourne. Because most enterprise businesses employ Linux these days, it's a greater chance you work with Bash. You can find out which shells are available on your Linux distribution by issuing the command:

cat /etc/shells

You'll then likely see this list:


Switch from Bash to Bourne shell

Although Bash is the default, Bourne (aka sh) is also available without having to install anything. To switch from Bash to Bourne, open a terminal window and follow these steps:

  1. Issue the command chsh
  2. Type your user password
  3. When prompted, type /bin/sh for the new shell
  4. Type su - USERNAME (replace USERNAME accordingly)
  5. Type your user password

If your switch to Bourne is successful, the new shell changes USER@HOSTNAME:~$ -- where USER is your username and HOSTNAME is the name of the computer -- to just $.

You should know that Bourne shell on most Linux distributions is an iteration; it's most likely a Portable Operating System Interface (POSIX) shell. In order to get the true Bourne shell, you'd have to be using FreeBSD or Unix.

While Bash uses the same grammar, parameter and variable expansion, redirection, and quoting as the Bourne Shell, Bash uses the POSIX standard in order to apply these features.

POSIX is an IEEE standard for the facilitation of application portability. POSIX creates a single, unified standard for Unix. As long as developers release an OS that matches the POSIX description, they can label their platform POSIX-compliant.

How do Bourne shell and Bash differ?

Bash is basically Bourne with more features; though, most of the commands work similarly, there are differences. Namely, interfaces and script compatibility.

The first difference with Bourne is that it doesn't come with all of the conveniences of Bash. One of the most obvious is color. With modern Bash, you'll see that different types of files are different colors.

For example, directories are blue; binary files are a shade of burgundy; and nonbinary, flat files are either black or white, depending on the color of your terminal.

Directory setup in Bash
Bash lists all directories in blue on Elementary OS.

Switch over to Bourne -- or its Linux equivalent -- and you'll see those blue directories are now just white text on a shaded terminal background.

Bourne interface
Once you switch to Bourne, everything is monochromatic.

For the longest time, on most modern Linux systems, /bin/sh was a link to /bin/bash, so you'd never know the difference between the two. As time marched on, Bash developed additional extensions to become more powerful and flexible than Bourne.

Eventually, Bourne was no longer an option on Linux; it was replaced by Bourne-compliant shells (like sh and dash). Even when you switch to the sh shell on Linux -- if you assume it to be Bourne -- most likely, you are using a more modern iteration.

Aside from color, the most important difference between the two shells is script compatibility. If you write a Bourne shell script, chances are very good it will run, without modification, on a Bash shell.

If you write a Bash shell script, it likely requires modification to run on a Bourne shell. If you know you'll write a script that is used on different shells, your best bet is to go with the Bourne shell compliance specifications.

Let's take a look at the Hello World shell script. Written for a Bourne shell, that script looks something like:

# Our Hello World script
echo Hello World

Written for Bash, that same script could look like:

# declare STRING variable
STRING="Hello World"
#print variable on a screen
echo $STRING

Both of these scripts run on the Bash and Bourne shells. Sort of. If you change your shell to sh on a modern Linux it will run, simply because you're likely using a POSIX-compliant shell. And because Bash is fully backward compatible with sh, the shell scripts written for sh work with Bash.

Because Bourne is not forward compatible with Bash, not every Bash script will run via the Bourne shell. If you ran the second script on FreeBSD, you might run into problems.

Next Steps

PowerShell vs. Bash: Key differences for Windows deployments

Dig Deeper on Data center ops, monitoring and management

Cloud Computing
and ESG