Table of contents
What is Kernel
The kernel is like the heart of an operating system. It connects software and hardware, handling resources like the CPU, memory, and devices. It gives important services to the operating system and apps, managing processes, memory, devices, and system requests. The kernel is vital for keeping the operating system secure and stable.
What is Shell
In computing, a shell is a tool that lets users communicate with an operating system by typing commands. The shell reads and carries out these commands, enabling users to do things like run programs, handle files, and control system resources. There are various types of shells, like the Bourne shell (sh), the C shell (csh), the Korn shell (ksh), and the widely used Bash shell (bash), which is the default on many Linux and macOS systems. Each shell has its own features and rules, but they all offer similar basic functions for working with the operating system.
What is Shell Scripting?
Shell scripting is all about writing a bunch of commands for the shell to run. It's a cool way to make your computer do things automatically, especially tasks you do over and over again or processes that involve lots of steps. In systems like Linux and macOS, which use shells like Bash, shell scripts are super handy.
These scripts are basically text files full of commands that the shell can run. You can spice them up with loops and if-else statements for some fancy logic. The best part? Shell scripting lets you automate stuff and build your own tools without having to deal with compiling code. It's like giving your computer superpowers!
What is#!/bin/bash?
can we write#!/bin/sh
as well?
#!/bin/bash
is called a "shebang" or "hashbang." It's a special sequence of characters at the beginning of a script that tells the operating system which interpreter to use to execute the script. In this case, #!/bin/bash
tells the system to use the Bash shell (bash
) to run the script.
Yes, you can use #!/bin/sh
as well. This tells the system to use the default shell interpreter (sh
), which is often a symbolic link or shortcut to another shell, such as Bash. Using #!/bin/sh
is more portable because it ensures that the script will run with the default shell interpreter on different Unix-like systems, even if sh
is not linked to bash
.
1. Write a Shell Script that prints I will complete #90DaysOofDevOps challenge
#!/bin/bash
echo "I will complete #90DaysOfDevOps challenge"
2. Write a Shell Script to take user input, input from arguments and print the variables.
#!/bin/bash
# Taking user input
echo "Enter your name:"
read name
# Taking input from arguments
arg1=$1
arg2=$2
# Printing the variables
echo "User input: $name"
echo "Argument 1: $arg1"
echo "Argument 2: $arg2"
3. Write an Example of If else in Shell Scripting by comparing 2 numbers.
#!/bin/bash
# Two numbers to compare
num1=10
num2=20
# Comparing the numbers
if [ $num1 -gt $num2 ]; then
echo "$num1 is greater than $num2"
elif [ $num1 -lt $num2 ]; then
echo "$num1 is less than $num2"
else
echo "Both numbers are equal"
fi