CMD, PowerShell, Bash - Some Basics
So, back to the interview I had about two weeks ago... and back to those tech questions I struggled with. The first two questions I wrote about (YAML files and Port numbers) I really had no answers for. The next two questions, I was at least not completely clueless about, even if a little unsure of myself and my knowledge.
So the next question I want to write about is:
What is a common Unix/Linux shell?
I hesitated. I use shells all the time, but the nuances of what a shell exactly is, the names of different types of shells, and what systems they exist on, I did not have a very confident understanding of and so my answer was no confident.
I always like to go back to basics, start at the beginning, and establish a fundamental understanding.
So, what is a shell?
According to Wikipedia, a shell in computing is a computer program that exposes an operating system's services to a human user or other programs. It allows that user or program to interact with the operating system. Generally, operating system shells use either a command-line interface (CLI) or a graphical user interface (GUI), depending on a computer's role and particular operation. It is named a shell because it is the outermost layer around the operating system.
I found this last insight from Wikipedia particularly useful, that the name shell in a sense actually explains its meaning as a shell around the operating system! Just like the term port I wrote about in my last article.
As developers, we often use a command-line interface to interact with the computer's operating system (or kernel) and programs we have installed on it to run our development projects. It requires us to be familiar with the specific commands for the shell we are using.
While there are similarities between many of the CLI shells there are also important differences. Depending on the type of computer and operating system you are using, there are different types of CLIs available to use.
CMD, PowerShell, and Bash
On Windows, the most common CLIs are Command Prompt (aka. cmd.exe or cmd) which was first released in 1987, and PowerShell which was released in 2006.
On Unix and Unix-like operating systems, such as Linux, there are many different shells available to use. Some of the common ones are:
- Bash (Bourne Again Shell)
- Zsh (Z Shell)
- Ksh (Korn Shell)
- Csh (C Shell)
With the Bourne Again Shell (bash) being the most widely used and thus the answer my interviewer was looking for.
I found a short article on ServerTribe by Uzair Ghalib that is really informative in summarizing the key differences between the three most common shells in use: CMD, Powershell, and bash. The following table is taken from the article:
CMD | PowerShell | Bash |
---|---|---|
CMD is the command line for Microsoft Windows operating system, with command-based features. | Powershell is a task-based command-line interface, specifically designed for system admins and is based on the .Net Framework. | Bash is a command-line and scripting language for most Unix/Linux-based operating systems. |
The generated output is in the form of characters. | Powershell treats input and output as objects. | Like CMD, Bash also treats input and output as text structures. |
CMD uses a text-based command-line interface. | Powershell has a more interactive graphical command-line interface CLI. | Bash has a simple user interface that is also text-based like CMD. |
It comes as a default program in all the windows operating systems. | In windows 2007 and above, Powershell is a built-in program. Before that, it has to be installed as a separate program. | Linux and Unix systems mostly use Bash, and it is used from the very first day in Linux and Unix operating systems. |
Uzair Ghalib concludes:
"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. Comparing Powershell and Bash is like comparing apples and oranges, they are used for different operating systems with different functionalities all over."
On a personal note.
Sometimes we can get so absorbed by the complexities of the advanced technologies we try to absorb that the fundamental, basic building blocks elude us. That was the personal sense I got from these interview questions. The interview questions motivated me to do a little bit of background reading on some of these fundamentals and share them with you.
As part of my own coding journey I have had the great fortune to be part of a very supportive Slack community and on more than one occasion I have reached out for help. One of the more experienced members has had to reiterate to me the function of shells and individual programs and how they interact on several occasions. Maybe now I can finally stop asking those basic questions.
And so can you! Unless you already had this all sorted out in your mind :) !
Thanks for reading!
Sources:
and
My favorite podcasters on Einfach Komplex also have an Episode about the topic: Episode 30 - but remember, it's in German!