Before understanding what is Bash shell, you must be familiar with the concepts of a command-line interpreter and Linux Shell (or sh).
What is a Command-Line Interpreter?
The term “command-line interpreter” refers to a program or text-based interface that sits between the user and the kernel and interprets the user’s typed input.
It will take the user’s typed input as a command and pass it to the kernel, which will return the resulting output to the interpreter and print it on the screen.
What is the Linux Shell (or sh)?
In Linux, the shell (or sh) is the command-line interpreter (or program) that provides an interface between the user and the kernel, taking stdin input from the user and giving the result as stdout output.
It sits on top of the kernel, takes the user input as commands like ls or awk, and prints the resulting output on the screen.
History of Linux Shell (or sh)
The shell, or sh (also known as Bourne Shell), is a programming language described by the POSIX standard for UNIX or UNIX-like operating systems.
It was a specification, not an implementation, which is why you will find many implementations of it like Dash, KSH, C Shell, and Bash.
On Ubuntu and Debian systems, “/bin/sh” is a symbolic/hard link to its implementation, Dash.
$ file /bin/sh /bin/sh: symbolic link to dash
Execute the following command to get the complete list of shells in your system:
$ cat /etc/shells # /etc/shells: valid login shells /bin/sh /bin/bash /usr/bin/bash /bin/rbash /usr/bin/rbash /usr/bin/sh /bin/dash /usr/bin/dash
The shell (or sh) was the replacement for the earlier UNIX shell, and the syntax for shell is identical to the syntax of the ALGOL68 programming language.
If you are writing a script, it is preferred to use shell (or sh) syntax to make your script compatible with multiple systems; it can even run in Bash without any modification as Bash is backwards compatible with sh.
It is also important to know that whenever you execute a shell script on your system, it is interpreted by your shell and not compiled like other programming languages.
Also Read: Beginners Guide for Bash Command in Linux
What is Bash?
Bash, an acronym for “Bourne-Again SHell“, is a superset of the shell (or sh) program written by Brian Fox for the GNU Project as a replacement for the traditional Bourne Shell (or sh).
Today, most of the Linux distributions ship Bash as the default login shell, which offers functional improvements over Bourne Shell (or sh) for both programming and interactive uses.
It was one of the first programs that Linus Torvalds (the creator of Linux) ported to Linux, and it was also the default shell in Apple until macOS Catalina was released in 2019, which replaced it with the Z shell, although Bash is still available as an alternate shell.
Due to being a superset of shell (or sh), it provides most of the functionality of the shell. However, it is not a valid POSIX shell. Rather, it is a dialect of the POSIX shell language.
It has many useful features like filename globbing (wildcard matching), piping, directory manipulation, job control, iteration, dynamic scope variables, and many more.
When Should You Use Bash or Shell (or sh)?
If you are a standard user with the basic requirement of command execution or terminal access, you don’t have to worry about it.
A script writer or advanced user can prefer to use shell (or sh) to write their script to standardize it across multiple systems that do not support Bash.
However, Bash is also a programming language that offers useful features like scoped variables and arrays to the basic shell (or sh).
At the end, it depends on your requirements and the scope of the user; that helps you decide which one to use.
Apart from that, you should also know.
If you were using the shell script with “#!/bin/sh” in the shebang line, you should expect the POSIX “sh” behavior.
However, if the shebang line is “#!/bin/bash“, it will be processed by the Bash interpreter.
And here we will end the article.
If you have any suggestions or improvements to add to this article, feel free to tell us in the comment section.
Join The Conversation
Users are always welcome to leave comments about the articles, whether they are questions, comments, constructive criticism, old information, or notices of typos. Please keep in mind that all comments are moderated according to our comment policy.