Linux Shell | What is Linux Shell in Hindi | Type of Shell In Linux | Linux Tutorial

 

Linux Shell , What is Linux Shell In Hindi | Type of Linux shell                                

 

You interact with shell indirectly if you use any major operating system. At the point when you utilize a terminal on Ubuntu, Linux Mint, or some other Linux dissemination, you are interacting with the shell.

In this article, I will describe the Linux shells and shell scripting. However, before we can comprehend shell scripting, we must first learn the following terms: Kernel, Shell and Terminal.

Prerequisites

You will need the following items to follow along with this tutorial:

In this article, I have used the Ubuntu version 20.04 operating system

  • Some knowledge on using Linux Operating Systems

Table of contents

  • What is the kernel
  • What is a Shell
  • Shell Scripting
  • Why do we need shell scripts
  • Easy demo of Bash Shell scripting

Click here to watch Video In Hindi ===>>>         

 

 

What is the kernel

The kernel is computer software that is at the heart of a computer’s operating system, controlling everything in it. It is in charge of the following Linux system’s resources:

  • File administration
  • Management of processes
  • Management of I/O
  • Device management, memory management, and so forth.

Linus Torvalds is sometimes misidentified as the creator of the Linux operating system, but he is only responsible for the creation of the Linux kernel.

A complete Linux kernel consists of:

  • The Kernel
  • The GNU system utilities and libraries
  • Additional management scripts
  • Installation scripts

What is a Shell

A shell is a unique user program that allows users to interact with operating system functions. Shell accepts user-readable commands and converts them to kernel-friendly. It is an interpreter for commands that can read and run commands on keyboards or files. When a user logs in or launches a terminal, the shell is launched.

Shells can be divided into two categories:

  1. Command-Line shell
  2. Graphical shell

Command-Line shell

Shell access is possible through a shell interface shell. A certain tool called ‘Terminal’ is used to key in human-readable commands like cat and ls in Linux/macOS or ‘command prompt’ in Windows, which subsequently carries out tasks. The user is then shown the result on the terminal. This is how an Ubuntu terminal looks like:

output

The ls command is used with the -l option in the screenshot above. For a long listing, the files are displayed in the current working directory.

Working with the command line shell can be challenging for beginners since there are so many commands to remember. It is extremely powerful because it allows users to save commands in a file and then execute them all at once. Any repetitious task can be easily automated this way. Batch records in Windows and Shell Scripts in Linux/macOS frameworks are normal names for these documents.

Graphical shell

Graphical shells allow the use of a GUI program for open, close, move and resize windows, as well as to switch focus between window sizes. Window Operating systems or Ubuntu Operating systems are notable examples of operating systems that provide a graphical user interface (GUI) for interacting with programs. For each activity, the user does not need to enter a command. A typical Ubuntu user interface is shown below:

output

For Linux systems, there are various shells available, such as:

Bourne Again Shell (BASH): In Linux systems, it is the most extensively used shell. It is the default login shell on Linux and macOS computers. The system is also Windows-compatible.

C Shell (CSH): The C shell is very much like the C programming language’s syntax and use.

Korn Shell (KSH): The Korn shell also served as the foundation for the POSIX Shell standard requirements, among other things.

Each shell accomplishes the same task, but it recognizes various commands and has distinct built-in functionalities.

Shell Scripting

Shells are usually interactive, so they accept and execute user commands. However, sometimes we need to regularly execute a range of instructions and we have to enter all commands each time on the terminal.

We can write and execute these commands in the shell to avoid this repetitive work because the shell can take the commands from the files as the input. Shell Scripts or Shell Programs are the names given to these files. The MS-DOS batch file is similar to the shell scripts. There is an extension to .sh in each shell script such as myscript.sh.

Shell scripts have the same syntax as other programming languages. If you are familiar with any programming language such as Python, C/C++, or others, they will be easy to create.

The following pieces make up a shell script:

  • Shell keywords such as if, else, and break
  • Shell commands such as cd, ls, echo, PWD, and touch
  • Functions
  • Control flow such as If...then...else, case and shell loops

Why do we need shell scripts?

Shell scripts come in handy for several reasons:

  1. To avoid repetitive work and the use of automation
  2. Shell scripting is used by system administrators to do routine backups
  3. Monitoring of the system
  4. Incorporating additional features into the shell

Advantages of shell scripts

  1. The programmer does not need to move to a different syntax because the command and syntax are identical to those typed directly on the command line
  2. Shell scripts are much faster to write than Java scripts
  3. Getting started quickly
  4. Debugging in real-time

Disadvantages of shell scripts

  1. Prone to costly blunders, a single blunder can change the directive, perhaps causing harm.
  2. Execution time is slow.
  3. Design defects in the syntax or implementation of the language
  4. Unlike other scripting languages, it is not well suited for large and sophisticated tasks and only provides a limited data structure

Easy demo of Bash Shell scripting

In this demo, we will do a bash script of incrementing a variable three times with an increment operator.

Procedure

  1. Open the terminal, move to the desktop directory, and run the following command to create a file and name it as firstscript.sh:
$  touch "name of the file"
  1. Run the ls -l command to view the permissions of the file you have created.

From the command above, the read and write permissions are enabled and no executable permission of the file is enabled.

  1. To enable the executable permissions, run the command below:
$  chmod +x "name of the file"
  1. Open the file you created and copy/paste the text below:
#!/bin/bash

VAR=1

echo "$VAR"


VAR=$((VAR+=1))
echo "$VAR"

VAR=$((VAR+=1))
echo "$VAR"

VAR=$((VAR+=1))
echo "$VAR"
  1. Run the command below to open the file you created:
$  ./"your file name"

It will display incremented variables 1 to 4 as shown below.

output

Conclusion

In the article, we have learned the basics of shell scripting, understood the terminologies used in shell scripting, the advantages, and disadvantages of shell scripting, and done an example of Bash shell scripting. I urge readers to use the knowledge learned above to create and learn more shell scripts to understand more about shell scripting.

 

 

What are the Different Types of Shells in Linux?

 

What are the Different Types of Shells in Linux?

While we believe that this content benefits our community, we have not yet thoroughly reviewed it. If you have any suggestions for improvements, please let us know by clicking the “report an issue“ button at the bottom of the tutorial.

Shells are an important part of any Linux user session. We are provided several different types of shells in Linux to accomplish tasks. Each shell has unique properties. Hence, there are many instances where one shell is better than the other for specific requirements.

This makes it important for us to be aware about the different types of shells available in Linux. In this tutorial, we will discuss what is a shell and why is it important.

Further, we will explore different types of shells in Linux to understand their functions and properties.

What is a Shell, and Why do we need them?

Whenever a user logs in to the system or opens a console window, the kernel runs a new shell instance. The kernel is the heart of any operating system.

It is responsible for the control management, and execution of processes, and to ensure proper utilization of system resources.

A shell is a program that acts as an interface between a user and the kernel. It allows a user to give commands to the kernel and receive responses from it. Through a shell, we can execute programs and utilities on the kernel. Hence, at its core, a shell is a program used to execute other programs on our system.

Being able to interact with the kernel makes shells a powerful tool. Without the ability to interact with the kernel, a user cannot access the utilities offered by their machine’s operating system.

Let’s understand the major shells that are available for the Linux environment.

Different Types of Shells in Linux

If you now understand what a kernel is, what a shell is, and why a shell is so important for Linux systems, let’s move on to learning about the different types of shells that are available.

Each of these shells has properties that make them highly efficient for a specific type of use over other shells. So let us discuss the different types of shells in Linux along with their properties and features.

1. The Bourne Shell (sh)

Developed at AT&T Bell Labs by Steve Bourne, the Bourne shell is regarded as the first UNIX shell ever. It is denoted as sh. It gained popularity due to its compact nature and high speeds of operation.

This is what made it the default shell for Solaris OS. It is also used as the default shell for all Solaris system administration scripts. Start reading about shell scripting here.

However, the Bourne shell has some major drawbacks.

  • It doesn’t have in-built functionality to handle logical and arithmetic operations.
  • Also, unlike most different types of shells in Linux, the Bourne shell cannot recall previously used commands.
  • It also lacks comprehensive features to offer a proper interactive use.

The complete path-name for the Bourne shell is /bin/sh and /sbin/sh. By default, it uses the prompt # for the root user and $ for the non-root users.

2. The GNU Bourne-Again Shell (bash)

More popularly known as the Bash shell, the GNU Bourne-Again shell was designed to be compatible with the Bourne shell. It incorporates useful features from different types of shells in Linux such as Korn shell and C shell.

It allows us to automatically recall previously used commands and edit them with help of arrow keys, unlike the Bourne shell.

The complete path-name for the GNU Bourne-Again shell is /bin/bash. By default, it uses the prompt bash-VersionNumber# for the root user and bash-VersionNumber$ for the non-root users.

3. The C Shell (csh)

The C shell was created at the University of California by Bill Joy. It is denoted as csh. It was developed to include useful programming features like in-built support for arithmetic operations and a syntax similar to the C programming language.

Further, it incorporated command history which was missing in different types of shells in Linux like the Bourne shell. Another prominent feature of a C shell is “aliases”.

The complete path-name for the C shell is /bin/csh. By default, it uses the prompt hostname# for the root user and hostname% for the non-root users.

4. The Korn Shell (ksh)

The Korn shell was developed at AT&T Bell Labs by David Korn, to improve the Bourne shell. It is denoted as ksh. The Korn shell is essentially a superset of the Bourne shell.

Besides supporting everything that would be supported by the Bourne shell, it provides users with new functionalities. It allows in-built support for arithmetic operations while offereing interactive features which are similar to the C shell.

The Korn shell runs scripts made for the Bourne shell, while offering string, array and function manipulation similar to the C programming language. It also supports scripts which were written for the C shell. Further, it is faster than most different types of shells in Linux, including the C shell.

The complete path-name for the Korn shell is /bin/ksh. By default, it uses the prompt # for the root user and $ for the non-root users.

5. The Z Shell (zsh)

The Z Shell or zsh is a sh shell extension with tons of improvements for customization. If you want a modern shell that has all the features a much more, the zsh shell is what you’re looking for.

Some noteworthy features of the z shell include:

  • Generate filenames based on given conditions
  • Plugins and theming support
  • Index of built-in functions
  • Command completion
  • and many more…

Let us summarise the different shells in Linux which we discussed in this tutorial in the table below.

    
ShellComplete path-namePrompt for root userPrompt for non root user
Bourne shell (sh)/bin/sh and /sbin/sh#$
GNU Bourne-Again shell (bash)/bin/bashbash-VersionNumber#bash-VersionNumber$
C shell (csh)/bin/csh#%
Korn shell (ksh)/bin/ksh#$
Z Shell (zsh)/bin/zsh<hostname>#<hostname>%

Wrapping up

Shells are one of, if not the most powerful tools available to a Linux user. Without shells, it is practically impossible for a person to utilise the features and functionality offered by the kernel installed on their system.

While we covered only the most commonly used types of shells in Linux, there are many other shell types worth exploring.

We hope this tutorial was able to help you to get understand the concept of shells, along with the properties of the different types of shells in Linux. If you have any feedback, queries, or suggestions, feel free to reach out to us in the comments below.


Please Share this course

It Looks like you have completed your course!! We have created Online series based on the above content. You can give a test and check your skill.




Be a Part of CollegeSpike by giving your precious comment here and help us in improving our content.