Day 4: Basic Linux Shell Scripting for DevOps Engineers.#90DaysOfDevOps

Before we move ahead to Shell Scripting in this blog we should know what is the shell, why it's used, and what relation it has with the kernel.
What is Kernel?
A kernel is a fundamental component of an operating system (OS). It serves as the bridge between the hardware of a computer and the software, enabling communication and management of resources. Here are the key aspects of a kernel:
Resource Management: The kernel manages computer resources, including CPU, memory, and peripheral devices. It allocates and schedules these resources to different processes and ensures they are used efficiently.
Hardware Interaction: It interacts directly with the hardware components, allowing software applications to communicate with devices such as hard drives, printers, and network interfaces.
Process Management: The kernel oversees the creation, execution, and termination of processes or tasks. It maintains process states, schedules them for execution, and provides inter-process communication mechanisms.
Memory Management: It manages system memory, allocating and deallocating memory for processes, ensuring data protection, and handling virtual memory.
File System Management: The kernel manages file systems, allowing the OS to read and write data to storage devices. It ensures data integrity and controls access to files and directories.
Security: Kernels play a crucial role in system security by enforcing access control and protecting against unauthorized actions. They implement user permissions and system integrity.
Device Drivers: The kernel includes device drivers, which are essential software components that enable communication between the OS and specific hardware devices. These drivers allow the OS to interact with hardware.
System Calls: Applications make requests to the kernel through system calls, which are interfaces that provide a secure and controlled way to access OS services.
In summary, a kernel is the core component of an operating system that manages the interactions between software and hardware, ensuring the system's stability, security, and efficient resource utilization.
What Is the Linux Shell?
The Linux shell is a command-line interface (CLI) that serves as an intermediary between users and the Linux operating system. It allows users to interact with the system by entering commands, executing scripts, and managing various aspects of the computer. Here are key aspects of the Linux shell:
Interface to the OS: The shell provides a text-based interface to the Linux operating system. Users can issue commands and receive responses, making it a powerful tool for controlling and configuring the system.
Command Execution: Users can run various Linux commands, such as creating, deleting, and managing files and directories, as well as performing system administration tasks.
Scripting: The shell supports scripting, enabling users to write custom scripts that automate tasks. These scripts are typically written in shell scripting languages like Bash.
Multiple Shells: Linux offers various types of shells, including Bash, Zsh, and Dash, each with its own features and capabilities. Users can choose the shell that best suits their needs and preferences.
Customization: Users can customize their shell environment by configuring settings, defining aliases, and creating startup scripts. This allows for a personalized and efficient workflow.
Redirection and Pipes: The shell supports input/output redirection and pipes, allowing users to control the flow of data between commands, making it a powerful tool for data processing.
Remote Access: Remote servers often use SSH (Secure Shell) to provide secure remote access to the shell, enabling system administration and file management from a distance.
In summary, the Linux shell is a versatile and essential component of the Linux operating system that provides users with the means to interact with the system, execute commands, and automate tasks through scripting.
What is Linux Shell Scripting?
Linux shell scripting refers to the practice of writing scripts or programs to automate and streamline tasks within the Linux operating system using the command-line interface (CLI). Here are key aspects of Linux shell scripting:
Scripting Language: Linux shell scripts are typically written in shell scripting languages like Bash, which is the default shell on many Linux distributions.
Automation: Shell scripts are used to automate repetitive tasks, making them more efficient and less error-prone. Tasks can include file management, system configuration, and more.
Commands: Shell scripts consist of a sequence of commands that are executed one after the other. These commands can be Linux shell commands or system commands.
Variables and Logic: Shell scripts can use variables to store and manipulate data, and they can include conditional statements and loops to add logic and decision-making capabilities.
Text-Based: Shell scripts operate in a text-based environment, which means they are human-readable and editable using a simple text editor.
File Extension: Shell scripts often have file extensions like ".sh" and are executed by invoking the script file using the shell.
Customization: Users can create custom shell scripts to tailor the Linux environment to their specific needs. This allows for a high degree of personalization.
Script Libraries: Various shell scripting libraries and resources are available to help users create scripts more efficiently and leverage existing solutions.
Linux shell scripting is a powerful tool for system administrators, developers, and power users who want to make the most of the Linux command-line interface by automating tasks and creating custom solutions.
Task:
What is
#!/bin/bashcan we write#!/bin/shas well?#!/bin/bashis a directive that tells the system to use the Bash shell as the interpreter to run the script. Also, we can use#!/bin/shas well because in this case we are specifying Bourne shell as interpreter to run the script whereas in#!/bin/bashwe are specifying bash shell as the interpreter.Write a Shell Script which prints
I will complete #90DaysOofDevOps challenge$ cat > myfirstshellscript.sh
#!/bin/bash
echo "I will complete #90DaysOfDevOps"chmod u+x myfirstshellscript.sh
I will complete #90DaysOfDevOps
Write a Shell Script to take user input, input from arguments and print the variables.
#!/bin/bash
echo "What is Your Name?"
read name
echo "What's your Age?"
read ageecho "Welcome, $name"
echo "$name is $age years old"Write an Example of If else in Shell Scripting by comparing 2 numbers
#!/bin/bash
echo "Enter the two numbers for comparison"
read n1
read n2
if [ $n1 -ge $n2 ]
then
echo "$n1 is bigger number"
else
echo "$n2 is bigger number"
fi




