What is Kernel
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
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?
A shell script is a computer program designed to be run by a linux shell, a command-line interpreter. The various dialects of shell scripts are considered to be scripting languages. Typical operations performed by shell scripts include file manipulation, program execution, and printing text.
Tasks
Explain in your own words and examples, what is Shell Scripting for DevOps.
What is
#!/bin/bash?
can we write#!/bin/sh
as well?Write a Shell Script that prints
I will complete the #90DaysOofDevOps challenge
Write a Shell Script to take user input, input from arguments and print the variables.
Write an Example of If else in Shell Scripting by comparing 2 numbers
Was it difficult?
- Post about it on LinkedIn and Let me know :)
Article Reference: Click here to read basic Linux Shell Scripting
YouTube Video: EASIEST Shell Scripting Tutorial for DevOps Engineers
What is Shell?
Shell is responsible for reading commands given by the user
Shell verifies the command and will give instructions to the kernel to process the command
If the command is invalid shell will give an error
The kernel will execute our command with system hardware components
Shell acts as a mediator between the user and the kernel
The file which contains all the commands for execution is called a Script file
Scripting
Scripting means a set of files mentioned in a file for execution
Scripting is used to automate our daily routine work
For example, I want to execute the below set of commands every day as a Linux user
Whoami
Pwd
Ls -lt
Instead of executing all these commands manually, we can keep it in a file and we can execute that file
The file which contains a set of commands it is called a script file
Shell scripting
Shell scripting is used to execute the set of commands using a script file
When we exe script file then will shell with reading those commands and will verify the syntax
Shell will give instructions to kernel
The kernel will give instructions to hardware components to perform the operation
Types of shells in Linux OS
Bourne shell
Bash shell
Korn shell
C shell
T shell
Z shell
Display all the shells in Linux
$cat /etc/shells
Display the default shell in Linux machine
echo $shell
echo is used to execute on terminal
Shell files should have the extension .sh
#!/bin/bash
and #!/bin/sh
are valid shebang lines, but they indicate different default interpreters. If you specifically want to use features or syntax unique to Bash, you should use #!/bin/bash
. If you want your script to be compatible with a broader range of Unix-like systems and shells, you might choose #!/bin/sh
.
Write a Shell Script that prints I will complete #90DaysOofDevOps challenge
#create a file with .sh as an extension
$ vi shell. sh
#paste the code inside the shell.sh file
#! /bin/bash
echo "I will complete #90DaysofDevOps challenge"
#execute the shell we created
$ sh shell.sh
#!/bin/bash
echo "I will complete #90DaysofDevOps challenge"
Write a Shell Script to take user input, input from arguments and print the variables.
#create a file with .sh as extension
$ vi shell.sh
#!/bin/bash echo $@ echo "please enter your name" read name echo " Hi $name, welcome to infosys" read -p "enter your designation" design echo "Please go to s3 building, floor 2 for $design section"
$ sh shell.sh Dear employee
Write an Example of If else in Shell Scripting by comparing 2 numbers
vi shell.sh