(Day-4) :Basic Linux Shell Scripting for DevOps Engineers

Motivated and goal-oriented aspiring DevOps engineer with a strong passion for optimizing software development and deployment processes
Hi DevOps Learners, we are back with #Day4 of the #90daysofdevops series and today we will be taking a look at the basics of Shell scripting that is needed if you are going to start your career as a DevOps engineer.
- Before deep diving into shell commands and scripting let's take a look at what is a Shell and some terms that we need to know to understand these concepts:
What is Kernel?
๐ฑ A kernel is like the core ๐ง of an operating system. It is the essential component that manages the system's resources and acts as a bridge ๐ between software and hardware.
The kernel is responsible for handling tasks such as memory management ๐งฎ, process management ๐, device drivers ๐ฅ๏ธ, and file system access ๐. It provides an interface for software applications to interact with the underlying hardware and ensures that different components of the system can work together harmoniously.
What is a Shell? ๐
๐ A shell in Linux is like a friendly ๐ค intermediary between you (the user) and the operating system. It provides a command-line interface (CLI) ๐ where you can type commands and perform various tasks. It's like a virtual ๐ช doorway to the system's resources.
There are different types of shells available, like the ๐ Bourne Shell (sh), the widely-used ๐ Bash (Bourne Again Shell), and the ๐ C Shell (csh). Each has its own set of features and syntax.
What is Linux Shell Scripting? ๐ง
- ๐ง Linux shell scripting is a combination of text-based commands, special symbols, and scripting constructs to create powerful scripts that can automate tasks and unleash the potential of the command-line interface (CLI).
Please see below architectural diagram to understand the Linux architecture on how the shell, the kernel, the hardware and utilities coordinate with each other :

What is #!/bin/bash? Can we write #!/bin/sh as well?
The
#!/bin/bashis called a shebang or a hashbang. It is a special construct used at the beginning of a script file to specify the interpreter or shell that should be used to execute the script. In this case,#!/bin/bashindicates that the script should be executed using the Bash shell.By specifying
#!/bin/bash, you ensure that the script is interpreted using the Bash shell.While
#!/bin/bashis commonly used, it is also possible to use#!/bin/shas the shebang in your script. This indicates that the script should be executed using the default system shell, which may be a different shell than Bash.
Write a Shell Script which prints
I will complete #90DaysOofDevOps challenge
#!/bin/bash
echo "I will complete #90DaysOfDevOps challenge"

Write a Shell Script to take user input, input from arguments and print the variables :
#!/bin/bash
echo "$@"
echo "Enter the challenge day number :"
read cnumber
echo "Good, lets get started with $cnumber"

Write an Example of If else in Shell Scripting by comparing 2 numbers:
#!/bin/bash
echo "Enter first number:"
read num1
echo "Enter second number:"
read num2
if [ $num1 -eq $num2 ]; then
echo "Numbers are equal"
elif [ $num1 -lt $num2 ]; then
echo " $num1 is smaller than $num2"
else
echo " $num1 is greater than $num2"
fi
Output in Terminal :

That's it for #day4. In the upcoming days we will be learning about topics like user management, file permissions, access control lists and many more. Till then, happy learning !!! Ciao!



