Basic Linux Shell Scripting for DevOps Engineers: Basic clearing guide | Day 4 of 90Days of Devops Journey.

ยท

4 min read

Basic Linux Shell Scripting for DevOps Engineers: Basic clearing guide | Day 4 of 90Days of Devops Journey.

TABLE OF CONTENTS:

๐Ÿค” What is a kernel? ๐Ÿง 

๐Ÿš What is the Shell? ๐Ÿš

๐Ÿš€ What is Linux 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 #90DaysOfDevOps 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. ๐Ÿงฎ

๐Ÿš€ DevOps Journey with Shell Scripting! ๐Ÿš

Hey friends! Today, I'll take you on a thrilling adventure through the world of DevOps and Shell Scripting.

Lets get Started๐Ÿ˜Ž

๐Ÿค” What is a kernel? ๐Ÿง 

The kernel is a central component of an operating system that manages the operations of a computer and hardware. It manages operations of memory and CPU time. It is a core component of an operating system. The kernel acts as a bridge between applications and data processing performed at the hardware level. It allows them to communicate with each other.

๐Ÿš What is the Shell? ๐Ÿš

A shell is a software program used to interpret commands that are input via a command-line interface, enabling users to interact with a computer by giving it instructions.

๐Ÿš What is Shell Scripting for DevOps?

Shell scripting is a powerful tool for DevOps engineers it acts like a magical spell to DevOps engineers because it allows them to automate repetitive tasks and streamline the deployment and management of applications.๐Ÿ“– ๐Ÿš

With shell scripting, DevOps engineers can write scripts to automate tasks such as installing software packages, configuring systems, setting up network connections, and managing files and directories. This reduces the manual effort required to perform these tasks, which in turn saves time and improves efficiency.

For example, suppose you want your computer to do tasks like creating folders, installing software, or even dancing with joy after completing a task. You can use shell scripts to make your computer follow your commands without you needing to click a hundred buttons. It saves time and effort! ๐ŸŽ‰

๐Ÿค” What is #!/bin/bash? Can we write #!/bin/sh as well?

๐Ÿ˜„ These special lines, starting with #! are called "shebangs." They tell your computer which interpreter (the one that reads and executes your script) to use. ๐Ÿง™โ€โ™‚๏ธ

#!/bin/bash means, "Hey computer, use the 'bash' interpreter to understand and run my script. Bash is like a language your computer speaks very fluently.

And yes, you can also use #!/bin/sh! It's like telling your computer to use /sh interpreter a more universal one that can still understand your commands but may lack some fancy tricks. ๐Ÿ˜Ž

๐Ÿ“ Shell Script: 90 Days of DevOps Challenge

With this tiny script, you can make your computer to print the script, "I will complete # 90-day DevOps challenge! ๐ŸŽ‰.

#!/bin/bash
# Get ready for the challenge!
echo "I will complete #90DaysOfDevOps challenge!"
#output
I will complete #90DaysOfDevops challenge!

๐Ÿ‘ค Shell Script: User Input and Arguments

This script is interactive! It will ask for your name and greet you.

#!/bin/bash
# Let's greet the user!
echo "Hello What's your name?"
# Read user input into a variable
read userName
# Print the user's name
echo "Hello $userName! I hope you like the script"
#output
# execute the script file
$ ./test1.sh
Hello What's your name?
John
Hello John! I hope you like this script

๐Ÿ”ข Shell Script: If-Else Example

In this script, we're comparing two numbers, num1 and num2. The script will tell you which number is greater or if they are equal! ๐Ÿค”

#!/bin/bash
# Two numbers for comparison
num1=42
num2=18
# Let's compare them!
if [ $num1 -gt $num2 ]; then
  echo "$num1 is greater than $num2."
else
  echo "$num1 is less than $num2."
fi
#output
42 is greater than 18

And that's all for today! I hope you enjoyed this information about basic Linux shell scripting for DevOps engineers. Stay tuned for more exciting content from my journey as a DevOps engineer.๐Ÿš€๐Ÿ’ป

#DevOps #Linux #ShellScripting # Automation #TWS #90DaysofDevOps

ย