Day 4: Basic Linux Shell Scripting for DevOps Engineers
What is Kernel:
The kernel is the core component of the operating system that acts as a bridge between the hardware and software, managing system resources, controlling input/output operations, and providing essential services to applications.
The kernel is responsible for managing system resources by allocating them to different processes and ensuring that they are used efficiently. It also provides a layer of abstraction between the hardware and software, which allows applications to interact with the hardware without needing to know the details of how the hardware works.
What is Shell:
The shell is the interface between the user and the operating system, providing a command-line environment to execute commands and scripts. The shell interprets user inputs, manages system processes, and enables the automation of tasks through scripting. It is a powerful tool that allows users to interact with the system and perform complex operations efficiently.
Shell Scripting for DevOps:
For DevOps professionals, a shell is an essential tool that enables them to automate tasks, manage server configurations, and deploy applications efficiently. The shell provides a command-line interface that allows developers and operations teams to interact with the system and perform complex operations.
What is #!/bin/bash? can we replace it with #!/bin/sh?
#!/bin/bash
is known as a shebang or hashbang, which is a special sequence of characters that specifies the interpreter that should be used to execute a script. In this case, #!/bin/bash
specifies that the script should be executed using the Bash shell.
Also, we can use #!/bin/sh
as a shebang. However, there is a difference between the two. #!/bin/sh
specifies that the script should be executed using the default shell interpreter, which is usually Bash on most Linux systems. However, it can also be another shell, such as Dash or KornShell, depending on the system configuration.
On the other hand, #!/bin/bash
specifically specifies the use of the Bash shell, which may be important if your script relies on Bash-specific features or syntax.
Shell Script which prints "I will complete #90DaysOofDevOps challenge":
This is a simple shell script that prints the message "I will complete #90DaysOfDevOps challenge" to the terminal.
Let's do shell scripting in VS Code:
"A Shell Script to take user input, input from arguments and print the variables":
This is a simple shell script that takes user input and prints a message to the terminal.
The script prompts the user to enter their name using the echo
command and then reads their input using the read
command. It then prompts the user to enter the name of the city where they live, reads their input again using the read
command, and finally prints a message that includes the city name they entered.
The message that is printed on the terminal will say "ohh {Name}!!! {Place}is a beautiful city", where {name, place}
is the name and the city that the user entered.
You can save this script with a .sh
extension, and execute it by running the command bash
script name. sh
(assuming the file is saved in the current directory).
Usage of If/else in Shell Scripting by comparing 2 numbers:
This is a simple shell script that uses an if-else statement to compare two numbers and print a message to the terminal.
The script sets the values of num1
and num2
to 2 and 5 respectively. It then uses the if
statement to compare the values of num1
and num2
using the -gt
operator, which checks if num1
is greater than num2
. If num1
is greater than num2
, the script will print the message "2 is greater than 5". If num2
is greater than num1
, the script will print the message "5 is greater than 2".
You can save this script with a .sh
extension
Let's experiment more
Thanks for Reading :)
Shubham Jangale