To understand the shell, first look at the following picture:
The shell is nothing more than a program that carries the user typed commands or instructions from the terminal and converts them into something that the kernel can understand.
If you’re using popular operating systems like Ubuntu, Kali Linux, Fedora, or Manjaro, you’re already interacting with Shell, knowingly or unknowingly.
But before deeply understanding the shell, you must understand the workings of the kernel.
What is a kernel?
From the picture, you can see that the kernel is the core component of the whole process, with complete control over every piece of hardware in your system.
It acts as a communicator between the software and hardware layers by managing the following resources:
- I/O Management
- File Management
- Process Management
- Memory Management
- Device Management
- Network Management, and many more.
The kernel is a standard program that resides in system memory in major systems to create a bridge between the hardware and the software.
Who is the Kingpin of Kernel?
Many people are often mistaken in thinking that Linus Torvalds is the man behind the development of the Linux operating system. But the fact is far from the truth; he is only responsible for the development of the Linux kernel.
An operating system is a combination of the following components:
I think that’s enough about the kernel; let’s move on to the shell.
What is a Shell?
The shell is the mediator between the user’s typed commands (or input) and the kernel that automatically gets started with your system boot.
To interact with shell, you use a program like terminal that opens a graphical window and lets you interact with the shell by taking input from you preceded by the dollar sign (“$
“).
The shell is not all about commands; it is divided into two categories:
- Command-Line Shell
- Graphical Shell
Command-Line Shell
The command-line shell is what most of you imagine when you think of shell, where you interact with the command-line interface.
A super amazing program known as “terminal” in Linux or MacOS or “command prompt” in Windows OS provides you interface to type human readable commands like “cat,” “ls“, “echo“, etc. and pass them to the shell for execution, printing the result on the terminal screen.
The command-line shell is way more powerful than the graphical shell, but the quality comes at a price. So, remembering tons of commands for beginners is like a stepping stone in the way.
However, to become a professional Linux user or programmer, you need to conquer this fear of the command-line shell and shine like a bright diamond (I know it’s over exaggerated).
Graphical Shell
The graphical shell is way simpler and beginner-friendly, especially for new computer users, and provides all the functionality like opening, closing, moving, and resizing windows, as well as switching focus between windows in the graphical user interface (GUI).
The Windows OS, macOS, and Ubuntu, Pop!_OS, Manjaro are good examples of operating systems that provide a GUI to the user for interacting with programs.
Types of Shell
It is common to confuse the meaning of “core shell” with “bash shell”. However, the core shell is the basic shell (also known as sh or Bourne Shell) 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 like:
- Bash shell: The most widely used and default login shell for major Linux and macOS systems.
- C Shell: The C shell is identical to the C programming language, sharing a command syntax.
- Korn Shell: The Korn Shell also served as the base for the POSIX Shell standard specifications, etc.
- Z Shell: My personal favorite provides extensive features, including plugin support.
Apart from them, there are many more shells in the market, and one more thing you should know is that different shells use different characters as prompts, like “$
” for Bash and “%
” for C and Z shells, respectively.
What is Shell Scripting?
The shell is not just a program but a whole programming language like Python or C/C++. You can write your own program, utility, or script that contains the if-else logic, loop statement, functions, variables, object, etc.
After you write your program, you can execute it using your default login shell. Note that your program will not be compiled like other programming languages but instead interpreted by your shell interpreter.
For example, the following is the basic shell script:
In the above script, five components of shell scripting are used: shebang, comments, variables, eval, and the echo command.
We have already written a detailed guide for each of these components, but below is a short description of them.
- Shebang: It is used to notify Shell which interpreter must be used to run the script file.
- Comments: It is used to improve the code readability or for debugging purposes.
- Variables: They are the pair of “
Key=Value
” that stores a string, integer, boolean, etc. - Eval: It will execute the arguments as a single command in the current shell environment.
- Echo: Take an argument as input and print the output on the screen.
Whenever you create a script file, you will give it executable permission using the chmod command.
$ chmod u+x [SCRIPT FILENAME]
After that, you will specify the relative or absolute path to run the script in the existing shell environment.
This is the basic example of a shell script, but you can write a more advanced program or script that can be a big contribution to the open-source community.
So, I will end it here.
I hope this digestible article will help you understand the concepts of kernel and shell, the difference between the shell and bash, and shell scripting.
However, if something is missing from the article or you have a good suggestion that must be added, 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.