SlideShare a Scribd company logo
1 of 41
GETTING STARTED WITH LINUX
COMMAND LINE ESSENTIALS
SHELL SCRIPT BASICS
USING VARIABLES
SHELL LOOPS
SHELL FUNCTIONS
www.edureka.co
USE CASES
BASIC OPERATORS
www.edureka.co
www.edureka.co
Why Linux?
open source operating system
access to source code
highly secure
runs faster
www.edureka.co
Why Linux?
open source operating system
access to source code
highly secure
runs faster
www.edureka.co
Why Linux?
open source operating system
access to source code
highly secure
runs faster
www.edureka.co
Why Linux?
open source operating system
access to source code
highly secure
runs faster
www.edureka.co
Why Linux?
open source operating system
access to source code
highly secure
runs faster
Linux is a Unix-like, open source and community-developed operating system for which is capable of handling activities from
multiple users at the same time.
What is LINUX?
www.edureka.co
Open-Source Community Developed Multiple Users
The computer programs that allocate the system resources and coordinate all the details of the computer's internals is
called the operating system or the Kernel. Users communicate with the OS through a program called the Shell.
What is a Kernel?
www.edureka.co
Applications
Kernel
Memory DevicesCPU
Apple uses its own signature operating system, XNU, which since 2001 has been derived from the Unix Kernel and known
as OS X. Before OS X came OS 9, otherwise known as "Classic“.
Kernel Applications : MAC OS
www.edureka.co
www.edureka.co
www.edureka.co
Command Line Interface
Console Representation
Difficult for Beginners
Faster OS
Granular Control
Graphical User Interface
Graphical Representation
Ease of Use
OS is slower
Lesser Control
CLI/Command Line Interface, is a text-based interface used to interact with software and operating system by typing
commands into the interface and receive a response in the same way.
What is CLI?
www.edureka.co
www.edureka.co
Scale Up
CLI/Command Line Interface, is a text-based interface used to interact with software and operating system by typing
commands into the interface and receive a response in the same way.
What is CLI?
www.edureka.co
Scale Up Control
CLI/Command Line Interface, is a text-based interface used to interact with software and operating system by typing
commands into the interface and receive a response in the same way.
What is CLI?
www.edureka.co
Scale Up Control
CLI/Command Line Interface, is a text-based interface used to interact with software and operating system by typing
commands into the interface and receive a response in the same way.
What is CLI?
Saves Memory
www.edureka.co
The Shell is a Command Line Interpreter. It translates commands entered by the user and converts them into a language
that is understood by the Kernel.
What is a Shell?
www.edureka.co
Translates
Commands
Language understood
by the Kernel
Takes Input
From User
The basic concept of a shell script is a list of commands, which are listed in the order of execution. A good shell script will
have comments, preceded by #sign, describing the steps
What is a Shell Script?
www.edureka.co
Translates
Commands
Language understood
by the Kernel
Takes Input
From User
www.edureka.co
BOURNE SHELL TYPES
Bourne Shell
Korn Shell
Bourne-Again Shell
POSIX Shell
C SHELL TYPES
C Shell
TENEX/TOPS C Shell
Z Shell
www.edureka.co
A variable is a character string to which we assign a value. The value assigned could be a number, text, filename, device, or
any other type of data.
What is a Variable?
www.edureka.co
A local variable is a variable that is present within the current instance of the shell. It is not available to programs that are
started by the shell. They are set at the command prompt.
Variable Types : Local Variable
www.edureka.co
Local Variable
An environment variable is available to any child process of the shell. Some programs need environment variables in order
to function correctly.
Variable Types : Environment Variable
www.edureka.co
Environmental VariableLocal Variable
A shell variable is a special variable that is set by the shell and is required by the shell in order to function correctly. Some
of these variables are environment variables whereas others are local variables.
Variable Types : Shell Variable
www.edureka.co
Environmental Variable Shell VariableLocal Variable
USING
VARIABLES
www.edureka.co
Defining Variables
Special Variables
Command Line Arguments
Special Parameters
Exit Status
www.edureka.co
BASIC
OPERATORS
www.edureka.co
Arithmetic Operators
Relational Operators
Boolean Operators
String Operators
File Test Operators
ARITHMETIC
OPERATORS
www.edureka.co
Operator Purpose Example
+ (Addition)
Adds values on either side of the
operator
`expr $a + $b` will give 30
- (Subtraction)
Subtracts right hand operand from left
hand operand
`expr $a - $b` will give -10
* (Multiplication)
Multiplies values on either side of the
operator
`expr $a * $b` will give 200
/ (Division)
Divides left hand operand by right hand
operand
`expr $b / $a` will give 2
% (Modulus)
Divides left hand operand by right hand
operand and returns remainder
`expr $b % $a` will give 0
= (Assignment) Assigns right operand in left operand a = $b would assign value of b into a
== (Equality)
Compares two numbers, if both are
same then returns true.
[ $a == $b ] would return false.
!= (Not Equality)
Compares two numbers, if both are
different then returns true.
[ $a != $b ] would return true.
RELATIONAL
OPERATORS
www.edureka.co
Operator Purpose Example
-eq
Checks if the value of two operands are
equal or not; if yes, then the condition
becomes true.
[ $a -eq $b ] is not true.
-ne
Checks if the value of two operands are
equal or not; if values are not equal,
then the condition becomes true.
[ $a -ne $b ] is true.
-gt
Checks if the value of left operand is
greater than the value of right
operand; if yes, then the condition
becomes true.
[ $a -gt $b ] is not true.
-lt
Checks if the value of left operand is
less than the value of right operand; if
yes, then the condition becomes true.
[ $a -lt $b ] is true.
-ge
Checks if the value of left operand is
greater than or equal to the value of
right operand; if yes, then the condition
becomes true.
[ $a -ge $b ] is not true.
-le
Checks if the value of left operand is
less than or equal to the value of right
operand; if yes, then the condition
becomes true.
[ $a -le $b ] is true.
BOOLEAN
OPERATORS
www.edureka.co
Operator Purpose Example
!
This is logical negation. This inverts a
true condition into false and vice versa.
[ ! false ] is true.
-o
This is logical OR. If one of the
operands is true, then the condition
becomes true.
[ $a -lt 20 -o $b -gt 100 ] is true.
-a
This is logical AND. If both the
operands are true, then the condition
becomes true otherwise false.
[ $a -lt 20 -a $b -gt 100 ] is false.
STRING
OPERATORS
www.edureka.co
Operator Purpose Example
= Checks if the value of two operands are
equal or not; if yes, then the condition
becomes true.
[ $a = $b ] is not true.
!= Checks if the value of two operands are
equal or not; if values are not equal
then the condition becomes true.
[ $a != $b ] is true.
-z Checks if the given string operand size
is zero; if it is zero length, then it
returns true.
[ -z $a ] is not true.
-n Checks if the given string operand size
is non-zero; if it is nonzero length, then
it returns true.
[ -n $a ] is not false.
str Checks if str is not the empty string; if
it is empty, then it returns false.
[ $a ] is not false.
FILE TEST
OPERATORS
www.edureka.co
Operator Purpose Example
-b file
Checks if file is a block special file; if
yes, then the condition becomes true.
[ -b $file ] is false.
-c file
Checks if file is a character special file;
if yes, then the condition becomes true.
[ -c $file ] is false.
-d file
Checks if file is a directory; if yes, then
the condition becomes true.
[ -d $file ] is not true.
-f file
Checks if file is an ordinary file as
opposed to a directory or special file; if
yes, then the condition becomes true.
[ -f $file ] is true.
-g file
Checks if file has its set group ID
(SGID) bit set; if yes, then the condition
becomes true.
[ -g $file ] is false.
-k file
Checks if file has its sticky bit set; if
yes, then the condition becomes true.
[ -k $file ] is false.
-p file
Checks if file is a named pipe; if yes,
then the condition becomes true.
[ -p $file ] is false.
FILE TEST
OPERATORS
www.edureka.co
Operator Purpose Example
-t file
Checks if file descriptor is open and
associated with a terminal; if yes, then
the condition becomes true.
[ -t $file ] is false.
-u file
Checks if file has its Set User ID (SUID)
bit set; if yes, then the condition
becomes true.
[ -u $file ] is false.
-r file
Checks if file is readable; if yes, then
the condition becomes true.
[ -r $file ] is true.
-w file
Checks if file is writable; if yes, then
the condition becomes true.
[ -w $file ] is true.
-x file
Checks if file is executable; if yes, then
the condition becomes true.
[ -x $file ] is true.
-s file
Checks if file has size greater than 0; if
yes, then condition becomes true.
[ -s $file ] is true.
-e file
Checks if file exists; is true even if file
is a directory but exists.
[ -e $file ] is true.
www.edureka.co
SHELL
LOOPS
www.edureka.co
The While Loop
The For Loop
The Until Loop
Nested Loops
Loop Control
www.edureka.co
SHELL
FUNCTIONS
www.edureka.co
Creating Functions
Passing Parameters to Functions
Returning Values from Functions
Nested Functions
Function Call from Prompt
www.edureka.co
www.edureka.co

More Related Content

What's hot (20)

Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Linux commands and file structure
Linux commands and file structureLinux commands and file structure
Linux commands and file structure
 
15 practical grep command examples in linux
15 practical grep command examples in linux15 practical grep command examples in linux
15 practical grep command examples in linux
 
Ch3 gnu make
Ch3 gnu makeCh3 gnu make
Ch3 gnu make
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
 
Bash shell scripting
Bash shell scriptingBash shell scripting
Bash shell scripting
 
What Can Compilers Do for Us?
What Can Compilers Do for Us?What Can Compilers Do for Us?
What Can Compilers Do for Us?
 
Linux Programming
Linux ProgrammingLinux Programming
Linux Programming
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Grep
GrepGrep
Grep
 
Easiest way to start with Shell scripting
Easiest way to start with Shell scriptingEasiest way to start with Shell scripting
Easiest way to start with Shell scripting
 
Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
 
Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013Unix Linux Commands Presentation 2013
Unix Linux Commands Presentation 2013
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 
Introduction to Makefile
Introduction to MakefileIntroduction to Makefile
Introduction to Makefile
 
SHELL PROGRAMMING
SHELL PROGRAMMINGSHELL PROGRAMMING
SHELL PROGRAMMING
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Introduction 2 linux
Introduction 2 linuxIntroduction 2 linux
Introduction 2 linux
 

Similar to Shell Scripting Tutorial | Edureka

Advanced linux chapter ix-shell script
Advanced linux chapter ix-shell scriptAdvanced linux chapter ix-shell script
Advanced linux chapter ix-shell scriptEliezer Moraes
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptxrani marri
 
Linux shell env
Linux shell envLinux shell env
Linux shell envRahul Pola
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics McSoftsis
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHPAhmed Swilam
 
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on phpSynapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on phpSynapseindiaComplaints
 
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on phpSynapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on phpSynapseindiaComplaints
 
php fundamental
php fundamentalphp fundamental
php fundamentalzalatarunk
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of phppooja bhandari
 
Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Roy Zimmer
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CDavid Wheeler
 

Similar to Shell Scripting Tutorial | Edureka (20)

SHELL PROGRAMMING.pptx
SHELL PROGRAMMING.pptxSHELL PROGRAMMING.pptx
SHELL PROGRAMMING.pptx
 
Spsl by sasidhar 3 unit
Spsl by sasidhar  3 unitSpsl by sasidhar  3 unit
Spsl by sasidhar 3 unit
 
Advanced linux chapter ix-shell script
Advanced linux chapter ix-shell scriptAdvanced linux chapter ix-shell script
Advanced linux chapter ix-shell script
 
php programming.pptx
php programming.pptxphp programming.pptx
php programming.pptx
 
Training on php by cyber security infotech (csi)
Training on  php by cyber security infotech (csi)Training on  php by cyber security infotech (csi)
Training on php by cyber security infotech (csi)
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell programming
Shell programmingShell programming
Shell programming
 
Linux shell env
Linux shell envLinux shell env
Linux shell env
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Learn PHP Basics
Learn PHP Basics Learn PHP Basics
Learn PHP Basics
 
Class 2 - Introduction to PHP
Class 2 - Introduction to PHPClass 2 - Introduction to PHP
Class 2 - Introduction to PHP
 
Unix
UnixUnix
Unix
 
PHP Basics
PHP BasicsPHP Basics
PHP Basics
 
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on phpSynapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on php
 
Synapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on phpSynapseindia reviews sharing intro on php
Synapseindia reviews sharing intro on php
 
php fundamental
php fundamentalphp fundamental
php fundamental
 
Php introduction with history of php
Php introduction with history of phpPhp introduction with history of php
Php introduction with history of php
 
php
phpphp
php
 
Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)Plunging Into Perl While Avoiding the Deep End (mostly)
Plunging Into Perl While Avoiding the Deep End (mostly)
 
Building and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning CBuilding and Distributing PostgreSQL Extensions Without Learning C
Building and Distributing PostgreSQL Extensions Without Learning C
 

More from Edureka!

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaEdureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaEdureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaEdureka!
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaEdureka!
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaEdureka!
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaEdureka!
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaEdureka!
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaEdureka!
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaEdureka!
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaEdureka!
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | EdurekaEdureka!
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEdureka!
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEdureka!
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaEdureka!
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaEdureka!
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaEdureka!
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaEdureka!
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaEdureka!
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | EdurekaEdureka!
 

More from Edureka! (20)

What to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | EdurekaWhat to learn during the 21 days Lockdown | Edureka
What to learn during the 21 days Lockdown | Edureka
 
Top 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | EdurekaTop 10 Dying Programming Languages in 2020 | Edureka
Top 10 Dying Programming Languages in 2020 | Edureka
 
Top 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | EdurekaTop 5 Trending Business Intelligence Tools | Edureka
Top 5 Trending Business Intelligence Tools | Edureka
 
Tableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | EdurekaTableau Tutorial for Data Science | Edureka
Tableau Tutorial for Data Science | Edureka
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Top 5 PMP Certifications | Edureka
Top 5 PMP Certifications | EdurekaTop 5 PMP Certifications | Edureka
Top 5 PMP Certifications | Edureka
 
Top Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | EdurekaTop Maven Interview Questions in 2020 | Edureka
Top Maven Interview Questions in 2020 | Edureka
 
Linux Mint Tutorial | Edureka
Linux Mint Tutorial | EdurekaLinux Mint Tutorial | Edureka
Linux Mint Tutorial | Edureka
 
How to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| EdurekaHow to Deploy Java Web App in AWS| Edureka
How to Deploy Java Web App in AWS| Edureka
 
Importance of Digital Marketing | Edureka
Importance of Digital Marketing | EdurekaImportance of Digital Marketing | Edureka
Importance of Digital Marketing | Edureka
 
RPA in 2020 | Edureka
RPA in 2020 | EdurekaRPA in 2020 | Edureka
RPA in 2020 | Edureka
 
Email Notifications in Jenkins | Edureka
Email Notifications in Jenkins | EdurekaEmail Notifications in Jenkins | Edureka
Email Notifications in Jenkins | Edureka
 
EA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | EdurekaEA Algorithm in Machine Learning | Edureka
EA Algorithm in Machine Learning | Edureka
 
Cognitive AI Tutorial | Edureka
Cognitive AI Tutorial | EdurekaCognitive AI Tutorial | Edureka
Cognitive AI Tutorial | Edureka
 
AWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | EdurekaAWS Cloud Practitioner Tutorial | Edureka
AWS Cloud Practitioner Tutorial | Edureka
 
Blue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | EdurekaBlue Prism Top Interview Questions | Edureka
Blue Prism Top Interview Questions | Edureka
 
Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka Big Data on AWS Tutorial | Edureka
Big Data on AWS Tutorial | Edureka
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | EdurekaA star algorithm | A* Algorithm in Artificial Intelligence | Edureka
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
 
Kubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | EdurekaKubernetes Installation on Ubuntu | Edureka
Kubernetes Installation on Ubuntu | Edureka
 
Introduction to DevOps | Edureka
Introduction to DevOps | EdurekaIntroduction to DevOps | Edureka
Introduction to DevOps | Edureka
 

Recently uploaded

Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfngoud9212
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Recently uploaded (20)

Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Bluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdfBluetooth Controlled Car with Arduino.pdf
Bluetooth Controlled Car with Arduino.pdf
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

Shell Scripting Tutorial | Edureka

  • 1.
  • 2. GETTING STARTED WITH LINUX COMMAND LINE ESSENTIALS SHELL SCRIPT BASICS USING VARIABLES SHELL LOOPS SHELL FUNCTIONS www.edureka.co USE CASES BASIC OPERATORS
  • 4. www.edureka.co Why Linux? open source operating system access to source code highly secure runs faster
  • 5. www.edureka.co Why Linux? open source operating system access to source code highly secure runs faster
  • 6. www.edureka.co Why Linux? open source operating system access to source code highly secure runs faster
  • 7. www.edureka.co Why Linux? open source operating system access to source code highly secure runs faster
  • 8. www.edureka.co Why Linux? open source operating system access to source code highly secure runs faster
  • 9. Linux is a Unix-like, open source and community-developed operating system for which is capable of handling activities from multiple users at the same time. What is LINUX? www.edureka.co Open-Source Community Developed Multiple Users
  • 10. The computer programs that allocate the system resources and coordinate all the details of the computer's internals is called the operating system or the Kernel. Users communicate with the OS through a program called the Shell. What is a Kernel? www.edureka.co Applications Kernel Memory DevicesCPU
  • 11. Apple uses its own signature operating system, XNU, which since 2001 has been derived from the Unix Kernel and known as OS X. Before OS X came OS 9, otherwise known as "Classic“. Kernel Applications : MAC OS www.edureka.co
  • 13. www.edureka.co Command Line Interface Console Representation Difficult for Beginners Faster OS Granular Control Graphical User Interface Graphical Representation Ease of Use OS is slower Lesser Control
  • 14. CLI/Command Line Interface, is a text-based interface used to interact with software and operating system by typing commands into the interface and receive a response in the same way. What is CLI? www.edureka.co
  • 15. www.edureka.co Scale Up CLI/Command Line Interface, is a text-based interface used to interact with software and operating system by typing commands into the interface and receive a response in the same way. What is CLI?
  • 16. www.edureka.co Scale Up Control CLI/Command Line Interface, is a text-based interface used to interact with software and operating system by typing commands into the interface and receive a response in the same way. What is CLI?
  • 17. www.edureka.co Scale Up Control CLI/Command Line Interface, is a text-based interface used to interact with software and operating system by typing commands into the interface and receive a response in the same way. What is CLI? Saves Memory
  • 19. The Shell is a Command Line Interpreter. It translates commands entered by the user and converts them into a language that is understood by the Kernel. What is a Shell? www.edureka.co Translates Commands Language understood by the Kernel Takes Input From User
  • 20. The basic concept of a shell script is a list of commands, which are listed in the order of execution. A good shell script will have comments, preceded by #sign, describing the steps What is a Shell Script? www.edureka.co Translates Commands Language understood by the Kernel Takes Input From User
  • 21. www.edureka.co BOURNE SHELL TYPES Bourne Shell Korn Shell Bourne-Again Shell POSIX Shell C SHELL TYPES C Shell TENEX/TOPS C Shell Z Shell
  • 23. A variable is a character string to which we assign a value. The value assigned could be a number, text, filename, device, or any other type of data. What is a Variable? www.edureka.co
  • 24. A local variable is a variable that is present within the current instance of the shell. It is not available to programs that are started by the shell. They are set at the command prompt. Variable Types : Local Variable www.edureka.co Local Variable
  • 25. An environment variable is available to any child process of the shell. Some programs need environment variables in order to function correctly. Variable Types : Environment Variable www.edureka.co Environmental VariableLocal Variable
  • 26. A shell variable is a special variable that is set by the shell and is required by the shell in order to function correctly. Some of these variables are environment variables whereas others are local variables. Variable Types : Shell Variable www.edureka.co Environmental Variable Shell VariableLocal Variable
  • 30. ARITHMETIC OPERATORS www.edureka.co Operator Purpose Example + (Addition) Adds values on either side of the operator `expr $a + $b` will give 30 - (Subtraction) Subtracts right hand operand from left hand operand `expr $a - $b` will give -10 * (Multiplication) Multiplies values on either side of the operator `expr $a * $b` will give 200 / (Division) Divides left hand operand by right hand operand `expr $b / $a` will give 2 % (Modulus) Divides left hand operand by right hand operand and returns remainder `expr $b % $a` will give 0 = (Assignment) Assigns right operand in left operand a = $b would assign value of b into a == (Equality) Compares two numbers, if both are same then returns true. [ $a == $b ] would return false. != (Not Equality) Compares two numbers, if both are different then returns true. [ $a != $b ] would return true.
  • 31. RELATIONAL OPERATORS www.edureka.co Operator Purpose Example -eq Checks if the value of two operands are equal or not; if yes, then the condition becomes true. [ $a -eq $b ] is not true. -ne Checks if the value of two operands are equal or not; if values are not equal, then the condition becomes true. [ $a -ne $b ] is true. -gt Checks if the value of left operand is greater than the value of right operand; if yes, then the condition becomes true. [ $a -gt $b ] is not true. -lt Checks if the value of left operand is less than the value of right operand; if yes, then the condition becomes true. [ $a -lt $b ] is true. -ge Checks if the value of left operand is greater than or equal to the value of right operand; if yes, then the condition becomes true. [ $a -ge $b ] is not true. -le Checks if the value of left operand is less than or equal to the value of right operand; if yes, then the condition becomes true. [ $a -le $b ] is true.
  • 32. BOOLEAN OPERATORS www.edureka.co Operator Purpose Example ! This is logical negation. This inverts a true condition into false and vice versa. [ ! false ] is true. -o This is logical OR. If one of the operands is true, then the condition becomes true. [ $a -lt 20 -o $b -gt 100 ] is true. -a This is logical AND. If both the operands are true, then the condition becomes true otherwise false. [ $a -lt 20 -a $b -gt 100 ] is false.
  • 33. STRING OPERATORS www.edureka.co Operator Purpose Example = Checks if the value of two operands are equal or not; if yes, then the condition becomes true. [ $a = $b ] is not true. != Checks if the value of two operands are equal or not; if values are not equal then the condition becomes true. [ $a != $b ] is true. -z Checks if the given string operand size is zero; if it is zero length, then it returns true. [ -z $a ] is not true. -n Checks if the given string operand size is non-zero; if it is nonzero length, then it returns true. [ -n $a ] is not false. str Checks if str is not the empty string; if it is empty, then it returns false. [ $a ] is not false.
  • 34. FILE TEST OPERATORS www.edureka.co Operator Purpose Example -b file Checks if file is a block special file; if yes, then the condition becomes true. [ -b $file ] is false. -c file Checks if file is a character special file; if yes, then the condition becomes true. [ -c $file ] is false. -d file Checks if file is a directory; if yes, then the condition becomes true. [ -d $file ] is not true. -f file Checks if file is an ordinary file as opposed to a directory or special file; if yes, then the condition becomes true. [ -f $file ] is true. -g file Checks if file has its set group ID (SGID) bit set; if yes, then the condition becomes true. [ -g $file ] is false. -k file Checks if file has its sticky bit set; if yes, then the condition becomes true. [ -k $file ] is false. -p file Checks if file is a named pipe; if yes, then the condition becomes true. [ -p $file ] is false.
  • 35. FILE TEST OPERATORS www.edureka.co Operator Purpose Example -t file Checks if file descriptor is open and associated with a terminal; if yes, then the condition becomes true. [ -t $file ] is false. -u file Checks if file has its Set User ID (SUID) bit set; if yes, then the condition becomes true. [ -u $file ] is false. -r file Checks if file is readable; if yes, then the condition becomes true. [ -r $file ] is true. -w file Checks if file is writable; if yes, then the condition becomes true. [ -w $file ] is true. -x file Checks if file is executable; if yes, then the condition becomes true. [ -x $file ] is true. -s file Checks if file has size greater than 0; if yes, then condition becomes true. [ -s $file ] is true. -e file Checks if file exists; is true even if file is a directory but exists. [ -e $file ] is true.
  • 37. SHELL LOOPS www.edureka.co The While Loop The For Loop The Until Loop Nested Loops Loop Control
  • 39. SHELL FUNCTIONS www.edureka.co Creating Functions Passing Parameters to Functions Returning Values from Functions Nested Functions Function Call from Prompt