Table of contents
What is Kernel?
The kernel is like the brain of your computer's operating system. It is a very important part that manages and controls everything that happens on your computer. It acts as a bridge between your hardware (like CPU, memory, and disk) and your software (like applications and games).
Whenever you do something on your computer, like clicking on an icon, playing music, or browsing the internet, the kernel is the one that makes it all happen smoothly. It makes sure that different programs can work together and that they don't interfere with each other.
What is Shell?
A shell is a user program that provides an interface for the user to use the operating system's services. Shell uses the human-readable commands from the user and converts them into something which the kernel can understand.
What is Linux Shell Scripting?
Linux shell scripting refers to the process of writing and executing a series of commands in a specific order within a text file (script) to perform tasks on a Linux or Unix-based operating system. It's like creating a recipe or set of instructions for the computer to follow.
Benefits:
Automation: Shell scripts enable you to automate repetitive and time-consuming tasks. Instead of executing a series of commands manually every time, you can create a script that performs those tasks automatically, saving you valuable time and effort.
Consistency: Shell scripts ensure that tasks are performed consistently and accurately every time you run the script. This helps avoid human errors that may occur when executing complex commands manually.
Reusability: Once you create a shell script, you can reuse it whenever needed. This reduces the need to rewrite commands repeatedly and promotes code reusability.
Task Simplification: You can simplify complex tasks by breaking them down into smaller, manageable steps within your script. This makes it easier to handle complex processes.
What is #!/bin/bash?
can we write #!/bin/sh
as well?
#!/bin/bash
is called a shebang or hashbang. It is a special line that appears at the beginning of a script file in Unix-like operating systems, including Linux. The shebang tells the system which interpreter should be used to execute the script. #!/bin/bash
specifies that the script should be interpreted and executed using the Bash shell (Bourne Again Shell), which is a popular and powerful shell commonly used in Linux.
Similarly, you can use #!/bin/sh
to specify that the script should be executed using the system's default shell, usually located at /bin/sh
. In most Linux distributions, /bin/sh
is a symbolic link to the system's default shell, which can be Bash, Dash, or another compatible shell.
Write a Shell Script that prints I will complete #90DaysOofDevOps challenge
vim challenge.sh
Press i for insertion
#!/bin/bash
echo "I will complete #90daysofdevops challenge"
Press esc then write :wq to save and exit
To run the script
bash challenge.sh
In case file has executable permission
./challenge.sh
Write a Shell Script to take user input, input from arguments and print the variables.
vim user_input.sh
#!/bin/bash
echo "Insert your input"
read user_input
echo "Your input is $user_input"
echo "this is value from argument: $1"
Press esc then write :wq to save and exit
./user_input.sh Passedarg
Write an Example of If else in Shell Scripting by comparing 2 numbers
#!/bin/bash
echo "Enter your number: "
read num
if [ $num -gt 3 ]; then
echo "Number is greater than 3."
else
echo "Number is 3 or less."
fi