Shell vs BASH vs PowerShell vs CMD

A. Yigit Ogun
6 min readMay 1, 2022

Today I was talking with one of my friend about a shell script. I noticed that she doesn’t comprehensively understand what are the difference in between Shell and PowerShell .Besides she even thought that Shell and Bash are the same thing. Her name is confidential, lol. So, I decided to publish an article about this topic.

A shell 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. A shell is software that allows users of an operating system to access the kernel’s services through a user interface. A shell can be invoked by the shell command in the command-line interface (CLI) on Unix- or Linux-based OS, letting people manage operations via specific commands, text, or script. Programming languages have their shells, which provide them independence from the operating system and allow cross-platform interoperability. Let’s dive in!

What is the Shell(sh)(Bourne Shell)?

The Unix operating system has a command-line interface known as a Shell also known as Bourne Shell. It collects data from you and runs programs depending on that data. The output of a program is displayed once it has completed its execution. Shell is a command-line interface that allows us to run commands, programs, and shell scripts. Shells come in a variety of flavours, much as operating systems come in a variety of flavours.

Bourne shell interaction on Version 7 Unix

Each Shell has its own set of commands and functionalities that are well-known. A shell script is just a set of commands that are listed in the sequence in which they should be executed. Comments, preceded by the # symbol, describe the steps of a decent shell script.

The shell issues the prompt, $, sometimes known as the command prompt. You can type a command while the prompt is shown. After you press Enter, Shell reads your input. It looks at the first word of your input to decide which command you wish to run. A word is a continuous string of characters. Words are separated by spaces and tabs. Shell scripts must include certain mandatory structures that instruct the shell environment what to do and when. Most scripts, however, are more complicated than the one above.

After all, the Shell is a full-fledged programming language with variables, control structures, and so on. A script is still just a series of commands executed in order, no matter how complex it becomes.

What is Bash(UNIX Shell)?

BASH stands for Bourne Again Shell, a clever term that pays homage to Bourne Shell. Bash is a shell program developed by Brian Fox as an update to the Bourne Shell application ‘sh.’ It’s a GNU project that’s open source. It was first introduced in 1989 as one of the most popular GNU/Linux shell distributions. It is more functional than Bourne Shell in terms of programming and interactive use.

It offers features such as command-line editing, key bindings, and endless command history. Bash is a command-line interpreter that runs in a text window and allows the user to interpret commands to do various tasks. A Shell Script is a sequence of these commands contained within a single file. A Shell Script can be read and executed using Bash.

Brian Fox — Author of GNU Bash

Bash is compatible with sh since it is based on the original UNIX Bourne Shell. It has the best and most useful features of the Korn and C shells, such as directory manipulation, job control, aliases, and so on. Key bindings in Bash allow you to create customized editing key sequences. Bash has one-dimensional arrays that make it simple to access and handle data lists.

The history of recently-visited directories within a list is specified by Directory Stack in Bash. For example, the pushd built-in is used to add a directory to the stack, the popd built-in is used to remove a directory from the stack, and the dirs built-in is used to display the directory stack’s content. For most Linux distributions and Apple’s macOS, Bash is the default login shell. It’s also available for Windows 10 with a Solaris 11 version and default user shell.

Screenshot of a Bash session

Bash Features

Bash provides a lot of flexibility and syntax that looks a lot like those of modern programming languages. Some of the notable features introduced in Bash are:

  • Command-line completion can be used to quickly complete a command using the <TAB> key
  • Command history through which we can quickly search for commands previously executed by using the <Up> arrow key or <CTRL-R>
  • Arithmetic evaluation without having to use external programs
  • Associative arrays, which enables us to create an array with string indices
  • Keyboard shortcuts for command-line editing
  • Customizability enables us to modify the default presentation offered by Bash

What is CMD(Command Prompt)?

CMD stands for Windows Command Prompt. When Microsoft DOS operating system was launched initially, CMD was used as a shell in it and the first version of CMD was released in 1987. The command prompt is the default command-line interpreter for Microsoft Windows and few other operating systems. CMD is usually used for carrying out different routine administration tasks and is also used to perform automation. All such tasks are performed using scripts and batch files in the command prompt. Command prompt has pre-built commands that are usually used to perform different operations such as CD, copy, paste, ping, etc.

What is PowerShell?

Welcome to the Microsoft side of the world. Microsoft Windows was never considered to be very good at task automation compared to Linux. It was because of the limited functionality of the command prompt. In 2002 Microsoft started working on a new command-line tool and it was called Monad. In 2006, the first version was released with the name Powershell. Powershell is an automated command-line shell and also has all the features & functionalities of CMD. The major update or difference in Powershell is that it is object-oriented. Its functionality is based on objects, very similar to object-oriented programming based on objects, functions, and methods. One great addition to the list of features in Powershell is command lets, usually called Cmdlets.

SUMMARY

To put it in a nutshell, each of the tools has its own benefits and usage according to the specific circumstances. Powershell is the advanced version of CMD with a lot of added functionalities and features. Moreover, it has a better graphical interface and better support for server automation tasks. And Bash is same for Shell. Comparing Powershell and Bash is like comparing apples and oranges, they are used for different operating systems with different functionalities all over. Thank you for reading and I hope it helps somebody out there.

RESOURCES

--

--

A. Yigit Ogun

42 Heilbronn ✦ AWS Community Builder ✦ DevOps ✦ Cloud ✦ C/C++ ✦ GNU/Linux ✦ https://linktr.ee/ayogun