#90DaysOfDevops | Day 4

Rajendra PatilRajendra Patil
3 min read

๐Ÿ“ŒWhat is Kernel?

A kernel is the core part of an operating system that manages the system's resources and communication between hardware and software. It acts as a bridge between applications and the actual data processing done at the hardware level. Essentially, the kernel ensures that various programs can run simultaneously and share the system's resources efficiently without interfering with each other.

๐Ÿ“ŒWhat is Shell?

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

๐Ÿ“ŒWhat is Linux Shell Scripting?

Linux shell scripting is writing a series of commands in a file to be executed by the Linux shell (the command-line interface). These scripts automate tasks, such as file manipulation, program execution, and system monitoring. By using shell scripts, users can save time and reduce the chance of errors when performing repetitive tasks.

๐Ÿ“ŒWhat is Linux Shell Scripting?

Shell script is a computer program designed to be run by Linux shell, Command Line Interpreter. Shell Scripting in DevOps is about to make thing automatically. It's like giving list of commands to run one by one without asking again and again.

๐Ÿ“ŒSteps for writing a Shell Script:

Step 1:

  • Use any editor of your choice like vim and create a file with .sh extension.

Step 2:

  • After writing the script execute permission of your scripts as follows.

    chmod +x <script_name>

    chmod 755 <script_name>

Step 3:

  • Execute your shell script as follows:

    sh <script_name>

    ./<script_name>

๐Ÿ“Œ What is #!/bin/bash? can we write #!/bin/sh as well?

The #!/bin/bash (shebang) is a special line at the beginning of a shell script that tells the system which interpreter should be used to execute the script. In this case, it specifies the Bash shell.

We can also write #!/bin/sh Shebang directs script to be executed by default shell, it might be Bash or Dash

๐Ÿ“ŒWrite a Shell Script which prints "I will complete #90DaysOfDevOps challenge" .

 #!/bin/bash
 echo "I will complete #90DaysOfDevOps challenge"

๐Ÿ“ŒWrite a Shell Script to take user input, input from arguments and print the variables.

#!/bin/bash

echo "Enter your name"
read username
echo "My name is : $username"

arg1=1
arg2=2

echo "Argument 1 is : $arg1"
echo "Argument 2 is : $arg2"

๐Ÿ“ŒWrite an Example of If else in Shell Scripting by comparing 2 numbers.

 #!/bin/bash
 # Comparing Two Numbers

#Prompt the user to enter two numbers
echo "Enter the first number:"
read num1

echo "Enter the second number:"
read num2

 if [ $num1 -gt $num2 ]; then
     echo "$num1 is greater than $num2"

elif [ $num1 -lt $num2 ]; then
     echo "$num1 is less than $num2"

else
     echo "Both numbers are equal"
 fi

I hope you found this guide on learning Shell scripting for DevOps engineers both enjoyable and valuable. If you did, please consider following and like it to show your support ๐Ÿ˜„.

Happy Learning !!

0
Subscribe to my newsletter

Read articles from Rajendra Patil directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rajendra Patil
Rajendra Patil