EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 600+ Courses All in One Bundle
  • Login

Shell Scripting Tutorial

Home » Software Development » Software Development Tutorials » Shell Scripting Tutorial

Shell Scripting Basics

What is Shell Scripting?

Uses of Shell Scripting

Shell Scripting Commands

Shell Script Parameters

Variables in Shell Scripting

Shell Script Argument

Execute Shell Script

Shell Script Set Variable

Shell Script Operators

Function in Shell Scripting

Echo in Shell Scripting

if condition in shell script

If Statement in Shell Scripting

If Else in Shell Scripting

Switch Case in Shell Scripting

Shell Script Case

Loops in Shell Scripting

For Loop in Shell Scripting

While loop in Shell Scripting

Shell Script Set

Shell Script Sleep

Shell Script Usage

Eval in Shell Script

Shell Script Read File

What is Bash?

What is Bash Scripting?

Bash Shell Script

Bash Script Arguments

Batch Scripting Commands

Bash Script Variables

Bash Set Variables

Bash Local Variables

Bash Variable in String

Bash Concatenate Strings

Bash Export Variable

Bash Alias

Bash Trim String

Bash Replace String

Bash Split String

Bash File

Shell Scripting Interview Questions

Bash String Length

Korn Shell Scripting

Shell Scripting Tutorial

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.

Why Shell Scripting?

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.

Types of Shell Scripts

There are majorly two types of shell scripts:- BASH and C Shell

  • Bourne again shells (BASH) is the default shell having $ as its prompt, it is the most popular shell used for creating and executing shell commands.
  • C Shell is capable enough to read file commands and character prompting C shell is %

Applications of Shell Scripting

Shell Scripts are used for many purposes some of them are like:-

  • Execution of any batch job.
  • Execution of any run on startup.
  • Running a program.
  • Linking of directories and files over.
  • Routine task execution.
  • Monitoring of Jobs.
  • Kernel level communication.
  • Root dir operations.

Example

Let us see a simple example for Shell Scripting:-

#!/bin/bash
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.

#!/bin/bash
echo "Enter the 1st number"
read x
echo "Enter 2nd number"
read y
(( 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.

Target Audience

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.

Prerequisites

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.

Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Java Tutorials
  • Python Tutorials
  • All Tutorials
Certification Courses
  • All Courses
  • Software Development Course - All in One Bundle
  • Become a Python Developer
  • Java Course
  • Become a Selenium Automation Tester
  • Become an IoT Developer
  • ASP.NET Course
  • VB.NET Course
  • PHP Course

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

Already registered !

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Special Offer - All in One Software Development Bundle (600+ Courses, 50+ projects) Learn More