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

What is Kernel?

The operating system of a computer is built around a single program known as the kernel, which has complete command and control over the entire system.

What is Shell?

A shell is a special user program that gives the user an interface to use services provided by the operating system. The user's commands are converted into something that the kernel can understand by Shell. It is an interpreter for the command language that runs commands that are read from files or input devices like keyboards. When the user starts the terminal or logs in, the shell is started.

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. Shell scripting for DevOps refers to the commands used to automate the tasks written in .sh file

What is #!/bin/bash?

#!/usr/bin/bash is a shebang line used in script files to set bash, present in the '/bin' directory, as the default shell for executing commands present in the file. It defines an absolute path /usr/bin/bash to the Bash shell.

Can we write #!/bin/bash? as #!/bin/sh ?

They're nearly identical but bash has more features – sh is (more or less) an older subset of bash . sh often means the original Bourne shell.

The best practice would be to not write #!/bin/bash? as #!/bin/sh
As bash and sh are two different shells. Basically bash is sh, with more features and better syntax. Most commands work the same, but they are different.

Having said that, you should realize /bin/sh on most systems will be a symbolic link and will not invoke sh. In Ubuntu /bin/sh used to link to bash, typical behavior on Linux distributions, but now has changed to linking to another shell called dash. I would use bash, as that is pretty much the standard (or at least most common, from my experience). In fact, problems arise when a bash script will use #!/bin/sh because the script-maker assumes the link is to bash when it doesn't have to be.

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

Input :

Output :

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

    Input :

Here $1 and $2 will be user input while running the command.
As shown in the below image.

Output:

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

Input :

Output :

I hope this blog pleased you.

#90DaysOfDevOps

#TrainwithShubham