Shell Scripting | Topic "Basic Concept"

Learning Shell Scripting

Hello Guys, Today I am starting a full new course of Basic To Mid Level Shell Scripting. We will learn about shell scripting by practically creating scripts for Linux system.Before creating our first script , We will learn some basics about shell scripting. If you already know about the basics you can skip this post & wait for our next post.

            For this you can use any Linux operating system but my recommendation is CentOS & Ubuntu. CentOS is freely available rpm base Linux distro where Ubuntu is freely available deb base distro and easy to install and use.


So Lets Start


First we will know what is Kernel : Kernel is the core part of Linux operating system. It is actually an Operating System which is responsible for managing, operating & controlling the system hardware & interpret between the system hardware & the user application. To learn more about Linux kernel visit this post

Shell: A human can not directly communicate with kernel that means Linux Kernel don't understand human readable commands. Because it only understand low level language. So in order to communicate with Kernel or given commands to kernel we need a middle-man who can translate the human readable commands to low level language that kernel can understand. Shell is that middle-man who does this job. So "Shell is interpreter  between user & the kernel. Shell takes commands from user & pass it to kernel , then its kernel's responsibility to execute the commands and finish the task".

            In Linux there are many shells available. They are used for specific purposes.Every shell has its unique properties & set of commands.A very popular & default in most Linux systems shell is BASH shell, Which stands for Bourne Again Shell.Some other shells are KSH shell ,CSH shell ,ZSH shell.


Shell Scripting: When you send a command to kernel with the help of shell command interpreter, It executes the command & give you the output. When you pass a set of commands to Kernel in a right manner that set of commands are called as script & this writing techniques are called shell scripting. So we can say a shell scripting is a writing techniques/skill by placing set of commands in a right manner in shell that UNIX/Linux Kernel can execute. Shell scripting is also considered as scripting language.




Starting A Shell: These days all the modern Linux operating systems come with graphical UI/UX support.You can access a shell by opening a CLI (command line Interface) terminal. Different OS has different shortcut keys to open CLI or you can go through the menu option to find out the default terminal in Linux or search for the terminal in search bar.



            Once you open the terminal , you can check the default shell for your system by running the below command.This will display the current default shell for the user who is currently login.

echo $SHELL




If you want to check all avaialbe shells in your system. you can read the file /etc/shells via cat command.



Executing A Script: You can create your scripts in any text editor like vim or nano & save it with the .sh extension. Then you have to give the execution permission to that file. Now your script is ready to run/execute.

There are two ways to run the scripts.

1) run scripts from absolute path : When you run your script by giving the complete path where the script is located.

example: /home/username/Desktop/scripts/helloworld.sh

2) run scripts from relative path : When you go inside the folder where the script is located then run the script.

cd /home/username/Desktop/scripts

./helloworld.sh

This is the basics about the shell & shell scripting. In next lesson we will start learning scripting from basics & then create our very first simple script.

Sharing is Caring😊

Post a Comment

0 Comments