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