DEV Community

Ayush Gupta
Ayush Gupta

Posted on • Edited on

Terminal vs Shell vs Bash vs Bash Scripting

Hi Everyone,

Let's try to understand some useful concepts in Linux OS

we will start with the terminal

Terminal -

we can consider, a terminal is a place or a GUI interface, where we can type our commands, and when we hit enter, we can see the output of the commands.

Now let's see, what happens when we hit enter after typing a command ?

you may be thinking, either the command will work and give us the desired output or it will fail and give us the error ?

but who is actually executing these commands ? and after execution how the output of the command is actually showing in the terminal window ?

In simple terms the commands are actually executing by the kernel

but its not like when we type a command in the terminal and hit enter and that command will reach kernel and kernel is able to execute it.

Shell -

It is actually the shell who is taking the commands from terminal and sending it the kernel for execution, and once command is executed, Kernel is going to send the output back to the shell and now shell is going to show it to the terminal.

Terminal -> Shell -> Kernel 
Enter fullscreen mode Exit fullscreen mode

Now let's consider a scenario, what if a command doesn't exist or there is a syntax error in our command, so in this case will the Shell, still going to send the command to the Kernel ?

so in the above scenario the shell is going to search first, and if the command doesn't exist, it will not send the command to kernel for execution, and we will simply get error as following -

bash: command_name: command not found
Enter fullscreen mode Exit fullscreen mode

Bash-

Now there are other types of Shells also, who are just reading the commands from Terminal and sending it to the Kernel for execution.

and the most common Shell is Bash

Bash Scripting -

So as of now we are typing the commands one at a time and when we hit enter, Shell is reading the command from terminal and sending to Kernel for execution right ?

now let's consider an example -

suppose you have 10 commands to follow to install some package in a server and you have to follow all the commands in a sequence, one way is to do it manually, which means we are going to type a command and hit enter, and once it is completed, we have to type the second command and hit enter .. continue

so as you can see in above scenario, we are typing each command manually, and then waiting for it also before completing and typing the next command and finally our package is installed in the server.

But now we have a roadblock, suppose we have 5 servers also, and in all the 5 servers, we have to install the same package, so shall we follow the same steps again and again in all the 5 servers ?

To solve this problem, we will be using Bash Scripting

Let's see how to create a script ?

we need put all the 10 commands which we were following manually in a file as following -

hello.sh

here "hello" is the name of the file, ".sh" is the file extension

#!/bin/bash

echo "Hello World"
Enter fullscreen mode Exit fullscreen mode

Now let's consider we have put all the 10 commands in out hello.sh file, now all we need to do is, is to run or execute this file using following way -

./hello.sh
Enter fullscreen mode Exit fullscreen mode

Now Shell will read this file line by line, and start sending the commands we have written in each line to the kernel for execution, until it has done reading all the lines of the file.

Now as you can see, we are not evening typing the commands in terminal also, we have just put all the commands in a file, Shell itself, is doing all the work automatically, now to solve the problem of installing the same package in all the 5 server, all we need to do is run the same script in all the 5 servers, that's all.

so using Bash Scripting we are able to automate the process of installing our packages in our servers.

Top comments (0)