# DAY-4 basic linux shell scripting

## *<mark>what is kernel?</mark>*

The kernel is a fundamental part of an operating system that acts as a bridge between the hardware and software components of a computer. It is responsible for managing the system's resources, such as memory, input/output devices, and CPU time, and providing a platform for running applications and processes.

The kernel is the core of the operating system, and all other components, such as device drivers, system libraries, and user interfaces, are built on top of it. It provides a set of services and abstractions that allow applications to interact with the hardware in a consistent and secure manner.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679656015801/3269105d-6f28-4e84-8bec-883f66a7babd.png?auto=compress,format&format=webp align="left")

## *<mark>What is Shell?</mark>*

In computing, a shell is a command-line interface (CLI) that provides an interface between the user and the operating system. It allows users to interact with the operating system and execute commands to perform various tasks, such as launching applications, managing files and directories, and manipulating system settings.

A shell is a special user program that provides an interface for the user to use operating system services. Shell accepts human-readable commands from users and converts them into something which the kernel can understand. It is a command language interpreter that executes commands read from input devices such as keyboards or from files. The shell gets started when the user logs in or start the terminal.

## ***<mark>What is Linux Shell Scripting?</mark>***

Shell scripts are computer programs that automate repetitive tasks and perform system administration functions on a Linux system. They manipulate files and directories, execute programs and commands, and print text to the command line interface. They provide a flexible and efficient way to manage system resources and improve performance for Linux system administrators and developers.

Shell scripts are also used to execute programs and commands on a Linux system. This can include launching applications, running batch processes, and performing system backups.

## *<mark>What is </mark>* `#!/bin/bash`*? <mark>Can we write </mark>* `#!/bin/sh` *<mark> as well</mark>?*

The shebang or hashbang at the beginning of a shell script (#!/bin/bash or #!/bin/sh) specifies which interpreter should be used to execute the script. `Bash` is an enhanced version of sh with more features and capabilities, while `sh` is a lightweight shell that is available on all Unix/Linux systems. Choosing the appropriate interpreter depends on the desired functionality and compatibility requirements of the script.

## *<mark>Wite a Shell Script which prints </mark>* `I will complete #90DaysOofDevOps challenge`

syntax:

`vi devops.sh`

`#!/bin/bash`

`echo " i will complete #90DaysOfDevOpsChallenge "`

`sh` [`devops.sh`](http://devops.sh)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679678224141/bc9e3908-88bc-4e84-85a9-4627d31cf44d.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679678185019/37ae3011-cd2b-4abd-a88e-4517248f7086.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679678268481/0b6e69e8-3d08-4c74-8c14-0456d3943e7a.png align="left")

## *<mark>Write a Shell Script to take user input, input from arguments and print the variables.</mark>*

syntax:

`vi 2script.sh`

`#!/bin/bash`

`echo " hey what's your name? "`

`read name`

`echo " how are you , $name ? "`

`read remark`

`echo " I am $remark too. "`

`sh 2script.sh`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679678758617/444f3afd-b1a7-4647-b7b7-0f8d1a2129ac.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679678728921/fe6a5c00-b7fe-4e3a-8025-109e82b86175.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679678946413/9dc94f81-1e07-42a4-ab2c-5155a52ec13e.png align="left")

## *<mark>Write an Example of If else in Shell Scripting by comparing 2 numbers</mark>*

syntax:

`vi` [`3script.sh`](http://3script.sh)

`#!/bin/bash`

`echo "enter your first number"`

`read num1`

`echo "enter your second number"`

`read num2`

`if [ $num1 -gt $num2 ]; then`

`echo "first number is greater than second number"`

`elif [ $num1 -lt $num2 ]; then`

`echo "second number is greater than first number"`

`else`

`echo "first number is equal to second number"`

`fi`

`sh` [`3script.sh`](http://3script.sh)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679679695307/1acda837-4b6c-4e50-85ce-595ebbda4830.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679679670650/e06aa0f6-02a6-48f5-afeb-d5587f234c18.png align="left")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1679679855623/a46bfbae-a3cb-44ff-87ae-88ac21bc70ae.png align="left")

Thank you for reading!!

~*Soumya Mallick*

Great initiative by the **#trainwithshubham** community. Thank you ***Shubham Londhe***

**#devops #90daysofdevops**
