What is Shell in Linux? — Top Tech Notes
When you start learning Linux commands the first thing that you encounter is Linux shell. Linux shell appear as an interface where you enter your commands. So in this post we will understand about Linux Shell.
To understand Linux Shell and Kernel we must first have understanding about Linux architecture. So let’s first discuss about Linux Architecture.
Linux Architecture is not something that is built using the hardware. By hardware part we mean the Laptop or the CPU. That is the middle part that you see in the figure below.
Hardware just cannot contact with the users directly. So let’s say we have a motherboard laying on the table. Then we cannot communicate with that motherboard directly because there is no common language between us and that motherboard lying on the table. So to enable this communicate between user and hardware we have kernel. This kernel is the middleman which basically contacts the hardware for us. We as users use the utilities or the application. Let’s suppose we are using the calculator application and we want to do arithmetic operations using the calculator. So when we start calculator or any other application if we give some command to the application then the first instruction is given to the shell. So if we try to multiply two numbers in calculator then the shell receives the command or interprets the information that user wants to multiply two numbers and it passes this information to kernel. So basically the shell instructs the kernel to do this particular operation. Now the kernel will understand what exactly is the operation that needs to be performed and it will push that to the hardware in a language which the hardware can understand such as the assembly language. Now the hardware will do the requested operation for us and will send it back to the shell from where users can view it.
So as a user we just type in the command and such as copy command or paste command but we do not know what happens inside and how it comes back to us. We just type in the command and we get the result in fraction of a second. We only see the monitor value where we type in the command in a shell. The shell acts as an interpreter to the kernel. So the kernel gets the command and it knows what to do. It does those operations with the help of hardware. The hardware sends the result back to the kernel which is then shown on the shell where we find that the operation has successfully completed. Or if there is an error then we can see the error message too.
So this is the Linux architecture. Now let’s understand Linux Shell.
A Shell interprets the commands that we have entered using a keyboard and sends it to the OS to perform them. As we just discussed in Linux architecture we have two entities — shell and the kernel. Now both shell and kernel are programs which are running on the operating system. So the operating system is what makes the shell and kernel possible. The kernel tries to communicate with the hardware and shell is the interface between the kernel and the user.
So now what shell does is, it interprets the commands which we as user enter into the system using keyboard or the mouse. Shell interprets and understand what these commands are trying to say and it translates and sends it to the operating system or the kernel to be precise. The kernel now understands what exactly should happen and so it uses the hardware help to complete those operations. And once it is done, kernel sends it back to the shell so that we can view it on our monitor. So this is the basic explanation of Linux shell.
How to use Shell?
Nowadays, we use a lot of GUI-based Linux distributions such as CentOS. There is also a CentOS server which is a command line interface but there is also graphical user interface. And like CentOS there is Ubuntu, Red Hat, Debian, Kali Linux etc. There are lots of Linux distributions which have GUI. So in the graphical operating system, how can we basically communicate with kernel with the user of a shell?
To emulate the purpose of a command line interface, all the GUI based distributions have a terminal within them. A terminal is basically an emulator or duplicate of command line interface. If you are familiar with Linux then you would have seen terminal atleast once. To open it you can simply right click on desktop and select terminal. If you open the terminal in your GUI based Linux systems, you will see a terminal like the one shown below.
On this terminal you will see you current logged in username@your system name. And then there will be a $ sysmbol after which you can enter your commands. You cans ee in figure above the I have entered the command “pwd” which shows my present working directory. Currently I am on desktop and that’s what the command is showing us on terminal. So this the emulated version of a command line interface.
So terminal in a GUI server emulates a command line interface of Linux server. Terminal emulators are more commonly used now due to GUI operating systems like Mac or Windows or Ubuntu. In Windows we have command prompt and powershell, in Mac we have terminal and in Ubuntu or CentOS Linux distribution we have terminal which emulates of duplicates the purpose of a command line interface server.
Top Shells in Linux
We have seen what is a Shell and how does an emulator of a shell looks like in a GUI based system. Now let’s look at the top shells in Linux. I our previous post we discussed that Linux is an open-source operting system. So obviously there are lots of contributors who creates different types of shell. But the most command or you say the default shell is the bash shell.
Bash shell: The elaboration of bash is Bourne Again Shell. It is the default shell in a lot of Linux distributions be it CentOS, Ubuntu or any other Linux distributions. We can further install other shells also. It is your wish. But bash is the most portable shell available.
Zsh or Z shell: There is also zsh or Z shell and it is similar to bash or an extended version of bash shell. So basically developers have taken the base linux operating system and created another operating system which has better features. So like that they took bash and added few features like sharing your command history across multiple terminals. So let’s say there are four different users using the same Linux operating system. They have different user names. So with Z shell you can share your command history with other users. This is one of the features but there are so many other useful features in Z shell.
Fish: Fish shell elaboration is Friendly and interactive shell. It is again an extended version of the common shell which is bash and has great features like auto completion of commands. So let’s say you need to type a long command but you do not want to type this long command then you can type first few letters of the command and hit tab button, and the command will get auto completed. So it is like and IDE with intellisense. So if you like intellisense feature then you can use Fish shell.
Tcsh: The Tenex C shell is extended version of C shell. So basically there is another shell called csh or the C shell which is written mostly in C programming language. This is why it is called as the C shell. And Tcsh is an extended version of it. Developers have taken C shell and added more capabilities to it. The plus point of Tcsh is that it is an scripting language because it will be similar for the users who already have experience in C programming. So this is the benefit of Tcsh. If you already have good experience with C programming, then you will find shell scripting pretty easy in Tcsh because it might have the same method of writing programs.
There are so many other shells available. You can do a simple google search and you will get information about several different shells. But the ones that we mentioned above are the top and one of the most popular shells.
To interact with a shell we enter commands. So if you type a command in shell such as “pwd” command to return present working directory then the shell understands that you are entering a command and it first validates the command, whether the particualr command that we entered is valid in this Linux distribution, then it further pushes it to the kernel. The kernel the executes the command with the help of hardware and then it gives back the result to shell. The shell then displays it to us so that we can view it. So this is the basic concept of Linux shell.
In next post we will discuss about Linux Kernel.
If you like this post, then do not forget to share this post with your friends and subscribe to our newsletter so that you can receive timely update whenever we publish any new post.
Subscribe to our newsletter!
Originally published at https://toptechnotes.com on July 9, 2022.