🚀 Day4: Basic Linux Shell Scripting 🐚 for DevOps 💻
What is a kernel?
In Linux, the kernel is the core part of the operating system responsible for managing hardware resources, process scheduling, memory management, and providing essential system services. It acts as an intermediary between software applications and hardware components.
The kernel plays a role in powering web servers. It acts as the foundation for web server software like Apache and Nginx, facilitating the hosting of websites and serving content to users worldwide.
What is Shell?
A shell is a command-line interface that allows users to interact with the operating system by typing text commands. It interprets these commands and communicates with the operating system kernel to execute them. Shells can also be used for scripting and automation tasks. Popular Linux shells include Bash, Zsh, and Fish. The user requests operate to the shell first and then the kernel executes it.
Imagine you're updating your Linux system. You open a terminal and use a shell command (e.g.,
sudo apt-get update), and the shell communicates with the OS to fetch and install the latest software updates.
Write a Shell Script that prints: I will complete the #90DaysOofDevOps challenge
Create a text file with the command
nanowhich ends with
nano myscript.sh. Every file that ends with
.shis a shell script file.
Then start the shell script with
#!/bin/bashand use the
echocommand to print the statement.
Then change the file permissions with
Execute the file by using
./<file_name>to print the content written in the file.
Write a Shell Script to take user input, input from arguments and print the variables:
As you know, first create a txt file with the
nanocommand that ends with
readcommand is used to get input from the user,
$sign is used to get the arguments e.g.
echois used to print the variables e.g.
echo "<statement>: <variable_name>"
Then change the permissions of the file with
chmodcommand as mentioned before.
./<bash_file_name>to show the content of the file.
Write an example of if else in Shell Scripting by comparing 2 numbers:
In the script file:
We define two numbers
if elseto compare two numbers.
-eqchecks if the numbers are equal.
fiused to close the
Depending on the result, the script prints the appropriate number.
You can modify the
'number2'to test the scenario.