# Day 4 Task: Basic Linux Shell Scripting for DevOps Engineers

## **What is Kernel:**

The kernel is one of the core sections of an operating system. It is responsible for each of the major actions of the Linux OS. This operating system contains distinct types of modules and cooperates with underlying hardware directly.

The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system.

## What is Shell:

![Record Your Desktop into Animated GIF via Linux Command - FOSTips](https://i0.wp.com/fostips.com/wp-content/uploads/2021/05/record-exec.gif?ssl=1 align="left")

It is an interface between the <mark>kernel</mark> and the <mark>user</mark>. It can afford the services of kernel. It can take commands through the user and runs the functions of the kernel.

## **Shell Types:**

1.sh

2.zsh

3.ksh

4.csh

5.bash

![A comparative study on shells in Linux: A review - ScienceDirect](https://ars.els-cdn.com/content/image/1-s2.0-S2214785320363902-gr1.jpg align="center")

## What is Linux Shell Scripting?

A Shell Script is a collection of <mark>Linux commands</mark> to be executed in sequence. The commands are written and stored in an ordinary text file. When the script is to be executed, the shell <mark>reads the file contents</mark>, <mark>interprets</mark>, and <mark>executes</mark> them as if they were typed on the shell command prompt.\[A shell script is a computer program designed to be run by a Linux shell, a command-line interpreter. Typical operations performed by shell scripts include file <mark>manipulation</mark>, <mark>program execution</mark>, and <mark>printing text</mark>\]

Using a shell script is most useful for **<mark>repetitive tasks that may be time-consuming to execute by typing one line at a time</mark>**. A few examples of applications shell scripts can be used for include: Automating the code compiling process. Running a program or creating a programming environment.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679585551671/af11b2f2-64b5-402b-830a-7bf8abbec7d9.png align="center")

## **Tasks:**

1. **Explain in your own words and examples, what is Shell Scripting for DevOps.**
    
    Shell is a command-line interpreter and shell script is nothing but a list of commands executed by the shell, Operations performed by the shell script include file manipulation program execution and printing text.
    
    *<mark>shell scripting in terms of DevOps used to automate tasks written in a .sh file.</mark>*
    
2. **What is** `#!/bin/bash?` **can we write** `#!/bin/sh` **as well?**
    
    This is known as shebang in Unix. Shebang is a collection of characters or letters that consist of a number sign and exclamation mark, that is (#!) at the beginning of a script
    
    #!/bin/bash at the start or top of the script to instruct our system to use bash as a default shell
    
    yes we can use <mark>#!/bin/bash or #!/bin/sh</mark>
    
    ### Difference between #!/bin/bash and #!/bin/sh:
    
    The shebang, #!/bin/bash when used in scripts is used to instruct the operating system <mark>to use bash as a command interpreter.</mark> Each of the systems has its own shells which the system will use to execute its own system scripts. This system shell can vary from OS to OS(most of the time it will be bash). Whereas, when the shebang, <mark>#!/bin/sh </mark> used in scripts instructs <mark>the internal system shell to start interpreting scripts.</mark>
    
3. Write a Shell Script which prints `I will complete #90DaysOofDevOps challenge`
    
    ```bash
    #!/bin/bash
    echo "I will complete #90DaysOfDevops challenge"
    ```
    
4. Write a Shell Script to take user input, input from arguments and print the variables.
    
    ```bash
    #!/bin/bash
    echo "Enter your name"
    read num
    echo "My name is $num"
    ```
    
5. Write an Example of If else in Shell Scripting by comparing 2 numbers
    
    <mark>save the script file with .sh extension and run as ./filename.sh on terminal/shell</mark>.
    
    ```bash
    #!/bin/bash
    num1=4
    num2=2
    if [$num1 -gt $num2]
    then
        echo "$num1 is greater"
    else
        echo "$num2 is greater"
    fi
    ```
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679586693037/19aa19be-1309-4e0c-b860-04b0694a5f58.png align="center")

*Thank you for reading this Blog. Hope you learned something new today! If you found this blog helpful, please like, share, and follow me for more blog posts like this in the future.*

I would like to connect with you at [**linkedin.com/in/madhuri-patil-278b19118**](http://linkedin.com/in/madhuri-patil-278b19118)
