Shell Scripting Basics
Shell Scripting basically is a series of commands given to shell for its execution. From Writing any command to reading and executing it all can be done with the help of shell scripting. We can run a single executable command or a series of commands that are given as input to the shell for various output related executions anytime.
Kernel being the internal part of an OS that communicates with hardware and software uses the shell as the outer part to communicate with the user. We give inputs in the form of scripts, command, etc and execute it for the desired results.
Shell scripting provides us with proper command and a platform to execute the commands with the desired input and generate the output needed. It works as a mediator to talk with the system kernel and various OS components.
We can simply think it as of a path or a way to a door that connects with the room we need for. So basically having the knowledge for shell scripting will ease the way we are willing to execute our commands further. We can start or stop any application together by just writing a simple script or we can initialize anything needed at the boot time with the help of shell scripting. It reduces the effort of a user by writing a series of commands at once.
There are majorly two types of shell scripts:- BASH and C Shell
Shell Scripts are used for many purposes some of them are like:-
Let us see a simple example for Shell Scripting:-
echo "Hello this is the Demo Run"
Simply saving the file with Demo.sh and running this will print on Hello this is the Demo Run on the terminal. We can implement any logic that we want to for our operations and can instruct the machine doing so.
Let us see a simple example for the Addition of two numbers.
echo "Enter the 1st number"
echo "Enter 2nd number"
(( add=x+y ))
echo "The result of addition=$add"
Saving and running this will give the output as Enter the 1st no, 4
Enter the 2nd no,5
The result of addition = 9.
So in this way, we can make our own scripts and make the execution successful.
Programmers having good knowledge over script writing, Linux, Unix and kernel systems in OS will find it easy to understand and write scripts. Having knowledge over loops and basic variable command makes this shell scripting easy and understandable.
For the reader, you should have a basic knowledge of kernel and Linux and Unix. How to implement a logic and normal variables values used would be an added advantage.