DAY 4 BASIC LINUX SHELL SCRIPTING FOR DevOps Engineer

#90daysofdevops


Basic Linux Shell Scripting for DevOps Engineers.

Tasks

1.Explain in your own words and examples, what is Shell Scripting for DevOps.

ans-> It provides an interface between the user and the kernel and executes programs called commands.
For example, if a user enters ls then the shell executes the ls command.

Shell is a command-line interpreter and Shell script is nothing but a list of commands executed by the shell. Shell scripting for DevOps refers to the commands used to automate the tasks written in . sh file.

what is kernel?

ans-> The kernel is a computer program at the core of a computer's operating system and generally has complete control over everything in the system. The kernel is a core component of an operating system and serves as the main interface between the computer's physical hardware and the processes running on it. The kernel enables multiple applications to share hardware resources by providing access to CPU, memory, disk I/O, and networking

2.What is #!/bin/bash? can we write #!/bin/sh as well?

ans-> This first line (#!/bin/bash or #!/bin/sh) has a name. It is known as ‘she-bang‘(shabang). This derives from the concatenation of the tokens sharp (#) and bang (!). It is also called as sh-bang, hashbang, poundbang or hash-pling. In computing, a she-bang is the character sequence consisting of the characters number sign and exclamation mark (#!) at the beginning of a script. -Bourne-again shell -present in the '/bin' directory, as the default shell for executing commands present in the file.

3.Write a Shell Script which prints I will complete #90DaysOofDevOps challenge

ans-> mkdir script

  • cd script
  • echo"I will be a great DevOps Engineer"

    -> nano devops_first.sh -> #!/bin/bash -> echo"I will be a great DevOps Engineer" -> conrol x +Y(yes) + tap(to save) -> bash devops_first.sh

4.Write a Shell Script to take user input, input from arguments and print the variables.

ans-> #!/bin/bash echo "I WILL BE A GREAT DEVOPS ENGINEER"

#echo $BASH name="NARAYAN" echo "hello ${name}"


nano devops_first.sh TOMY #argument

#!/bin/bash

echo "I WILL BE A GREAT DEVOPS ENGINEER"

#echo $BASH

name="Sushmita"

echo "hello ${name},please enter your age"

read age

echo "my age is ${age}"

echo "sub:hello,$1" #argument passing

sleep 2

echo "Me:hey how you doing"

sleep 2

echo "sub: I am doing good,thankyou"

5.Write an Example of If else in Shell Scripting by comparing 2 numbers

ans-> nano if_test.sh

#!/bin/bash

-echo "enter two number" -read a b -echo "a = $a" -echo "b = $b"

-if [ $a = $b ] -then

  • echo "a and b is equal " -else
  • echo "b and a is'not equal" -fi

#!/bin/bash

-if [ "$1" = "like" ] -then

  • echo "hey please $1 this post" -else
  • echo "OK,comment" -fi ./if_test.sh like