Shell scripting in Linux is a powerful tool that serves as the backbone of many automated processes in DevOps practices. As a technical blog writer with 15 years of experience in the field of DevOps, I've seen firsthand the transformational impact that adept use of shell scripting can have on both the efficiency and reliability of software development and operations.
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 a special user program that provides an interface for the user to use operating system services. Shell accepts human-readable commands from user and converts them into something 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 starts the terminal.
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.
Basic Shell Script
#!/bin/bash
echo "This is a Basic Shell Script"
echo "Complete 90 Days of DevOps Challenge and Become a DevOps Master"
#All commands can be written here.
#These are Comments in Linux
#file extension must be .sh
Running a Shell Script
Before we actually run the shell script we have to make fil executable and give executable permissions for user.
chmod 744 file.sh , will add executable permission to user and making it executable.
file.sh - Used to run the shell script
Shell Script to Check if A Number is Even or Odd
#!/bin/bash
echo "Script to Check if a Number is Even or Odd"
echo "Enter a Number: "
read number;
if[$num%2==0]; then
echo "It is a Even Number"
else
echo "It is an Odd Number"
fi