Getting started with Shell Scripting | Shell Scripting tutorial

Getting started with Shell Scripting | Shell Scripting tutorial

Hello Guys, Welcome to this tutorial series. In this tutorial series we are going to learn shell scripting and only part that is important with respect to DevOps perspective.

Before getting started with shell scripting and Linux shell you need to understand few concepts and those are

  • Kernel
  • Shell
  • Terminal

Now let's start with basic terminologies as i mentioned above

Kernel

Kernel is a computer program who talks with computer hardware like CPU, RAM and Disks and manages resources. It also allocates resources to applications that are running on top of kernel.

As shown in below diagram you can understand the flow.

Kernel shell and hardware interaction flow

Shell

Shell is a special computer program who interacts with kernel by converting human readable commands into kernel understandable language.

Usually in UNIX or Linux it is bash shell. For MAC users it is ZSH shell. In the following diagram you can see how exactly shell is working with kernel and computer hardware.

kernel working with shell

There are few shell available but for Linux and UNIX systems default shell is either BASH or SH.

You can check your system default shell by using command echo $0 and to list all shell types available on your system you can use command cat /etc/shells

bash, zsh, sh, ksh, tsh, fish, csh are few types of shell so comment what is your system default shell type is

Terminal

Terminal is a graphical window or a computer program which provides a CLI view to interact with shell and run shell commands and it also shows output.

ubuntu terminal

Now that out key terminologies are clear we can start with Linux shell scripting

Shell Scripting

Shell Script is a program which holds set of shell commands and execute them line by line as instructed in script file by user. Shell script is ran by system shell on which user runs the script and it return output for each command user written in script file.

Advantages:

Writing shell script is quick, Programming syntax is very easy, most of commands are similar to UNIX commands, can be used for automation.

Disadvantages

Shell scripting is not suited for large task, very minimal data structure.

Basic Shell Scripting Syntax

#!/bin/bash

# echo is a unix command which print data on terminal window
echo "hello friends"

Here in this template #!/bin/bash specifies the interpreter which system going to use for execution of the script. If we write script file without this first line then system default interpreter will be used. You can find system default shell interpreter by command echo $0 and you can list all available shell interpreter by command cat /etc/shells

Summary

This is all about "Getting started with shell scripting". In next blog we will start with variables in shell scripting and our first shell script.

Thanks for reading this article and please subscribe for such more articles.

Comment your doubts below this post so that I can react out to you and we can solve your quires.