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.
Example:
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.
Example:
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
nano
which ends with.sh
. Likenano myscript.sh
. Every file that ends with.sh
is a shell script file.Then start the shell script with
#!/bin/bash
and use theecho
command to print the statement.Then change the file permissions with
chmod
command.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
nano
command that ends with.sh
. e.g.nano user-input.sh
.Then
read
command is used to get input from the user,$
sign is used to get the arguments e.g.$1
, andecho
is used to print the variables e.g.echo "<statement>: <variable_name>"
Then change the permissions of the file with
chmod
command as mentioned before.Then use
./<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
'number1'
and'number2'
.We use
if else
to compare two numbers.-eq
checks if the numbers are equal.fi
used to close theif else
function.Depending on the result, the script prints the appropriate number.
You can modify the
'number1'
and'number2'
to test the scenario.