Day 4 - Basic Linux Shell Scripting for DevOps Engineers💻

Day 4 - Basic Linux Shell Scripting for DevOps Engineers💻

🌟What is Kernel?

The kernel is the heart of a computer's operating system, managing all interactions between software and hardware. It controls functions like CPU scheduling, memory management, and device communication. By efficiently managing system resources, the kernel ensures smooth operation and stability, making it a crucial component in any computing environment.

🌟What is Shell?

A shell is a command-line tool that lets users interact with the operating system. It takes text commands and turns them into actions performed by the system. Think of the shell as a link between you and the complex processes running in the background.🖥️➡️💻

🔑Key Functions of a Shell

  1. Command Execution:

    • The shell allows you to execute commands to manage files, run applications, and control the system.

    • Example: ls to list files, cd to change directories.📂

  2. Scripting:

    • Shells can execute scripts, which are collections of commands saved in a file, to automate tasks.

    • Example: A script to back up important files daily.📜

  3. Customisation:

    • Users can customize their shell environment with variables, aliases, and functions to enhance productivity.

    • Example: Setting the PATH variable to include custom directories.🛠️

  4. Job Control:

    • The shell can manage multiple tasks, allowing you to run processes in the foreground or background.

    • Example: Running a long process in the background using &.🔄

🌟What is Linux Shell Scripting?

Linux shell scripting is a powerful tool that lets users automate tasks, manage systems, and streamline workflows using the shell. It's an important skill for anyone working in Linux environments, especially in system administration, DevOps, and development. 🐧💻

What is Linux Shell Scripting for DevOps? 🤖

Linux shell scripting is a powerful tool for DevOps engineers, allowing them to automate tasks and streamline their workflows. By writing scripts, DevOps engineers can automate repetitive tasks, such as deploying code or managing infrastructure, saving time and increasing efficiency.

What is #!/bin/bash? Can we write #!/bin/sh as well? 🤔

#!/bin/bash is known as a shebang or hashbang. It specifies which interpreter should be used to execute the script. In this case, it specifies that the script should be run using the bash shell. Yes, you can also write #!/bin/sh, which specifies that the script should be run using the sh shell.

Example 1: Write a Shell Script that prints “I will complete #90DaysOfDevOps challenge” 📝

Here’s an example of a simple shell script that prints “I will complete #90DaysOfDevOps challenge”:

#!/bin/bash
echo "I will complete #90DaysOfDevOps challenge"

Example 2: Write a Shell Script to take user input, input from arguments, and print the variables

#!/bin/bash
echo "Enter your name:"
read name
echo "Hello $name!"
echo "You entered $# arguments: $@"

Example 3: Write an Example of If-else in Shell Scripting by comparing 2 numbers

#!/bin/bash
num1=5
num2=10
if [ $num1 -gt $num2 ]
then
    echo "$num1 is greater than $num2"
else
    echo "$num1 is less than $num2"
fi

"Today, we hope you enjoyed learning about basic Linux shell scripting for DevOps engineers".💻