sh vs bash : A summary

Varun Kumar
2 min readOct 11, 2017

--

If you are reading this then there is a good chance that you have come across the terms shell, sh, bash etc in the past. These terms may sound confusing and as they are closely related that makes the problem even worse. So I decided to write this post with the aim of trying to explain the differences between them.

Shell vs Kernel

Before moving forward it is important that we understand what the terms shell and kernel mean.

Kernel

The kernel is the hub of the operating system. It is responsible for doing things like interacting with hardware, do file I/O, and spawn off processes.

Shell

The shell acts as an interface between the user and the kernel. Technically speaking, a shell is a command line interpreter, i.e. the program that either interprets the command you enter in your terminal emulator (interactive mode) or processes shell scripts (text files containing commands).

Now that we have an idea of what the shell and kernel are, we can try to understand sh and Bash.

sh

Strictly speaking, sh (or the Shell Command Language) is a programming language described by the POSIX standard. The key here is that sh isn’t really a programming language in itself. It is just a specification. Specification is a detailed description of the syntax and semantics of that language. Specification doesn’t include an implementation.

Bash

There are different operating systems with their own shells and kernel. Bash is the shell for the GNU operating system. But we can also say that bash is a programming language.

Wait, isn’t that confusing? Is bash both a shell and a programming language?

Think of python. We can also start Python in interactive mode and it behaves like a shell. Or JavaScript, or Ruby or any scripting language.

Makes sense?

So bash is a programming language that can be thought of as an implementation of sh (although that has changed with time).

To summarize, sh is a specification, bash is the implementation.

--

--