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

Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask PresentationParag Mujumdar
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in LinuxAnu Chaudhry
 
Linux command ppt
Linux command pptLinux command ppt
Linux command pptkalyanineve
 
Docker Networking Overview
Docker Networking OverviewDocker Networking Overview
Docker Networking OverviewSreenivas Makam
 
Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署Bo-Yi Wu
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commandsSagar Kumar
 
Quick Guide with Linux Command Line
Quick Guide with Linux Command LineQuick Guide with Linux Command Line
Quick Guide with Linux Command LineAnuchit Chalothorn
 
Introduction to Kubernetes with demo
Introduction to Kubernetes with demoIntroduction to Kubernetes with demo
Introduction to Kubernetes with demoOpsta
 
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...Edureka!
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programmingsudhir singh yadav
 
Advanced perl finer points ,pack&unpack,eval,files
Advanced perl   finer points ,pack&unpack,eval,filesAdvanced perl   finer points ,pack&unpack,eval,files
Advanced perl finer points ,pack&unpack,eval,filesShankar D
 
Basic command ppt
Basic command pptBasic command ppt
Basic command pptRohit Kumar
 
Linux Administration
Linux AdministrationLinux Administration
Linux AdministrationHarish1983
 

What's hot (20)

Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Python/Flask Presentation
Python/Flask PresentationPython/Flask Presentation
Python/Flask Presentation
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
 
Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
 
Docker by Example - Basics
Docker by Example - Basics Docker by Example - Basics
Docker by Example - Basics
 
Basic 50 linus command
Basic 50 linus commandBasic 50 linus command
Basic 50 linus command
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Docker Networking
Docker NetworkingDocker Networking
Docker Networking
 
Docker Networking Overview
Docker Networking OverviewDocker Networking Overview
Docker Networking Overview
 
Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署Drone CI/CD 自動化測試及部署
Drone CI/CD 自動化測試及部署
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Vi editor
Vi editorVi editor
Vi editor
 
Quick Guide with Linux Command Line
Quick Guide with Linux Command LineQuick Guide with Linux Command Line
Quick Guide with Linux Command Line
 
Introduction to Kubernetes with demo
Introduction to Kubernetes with demoIntroduction to Kubernetes with demo
Introduction to Kubernetes with demo
 
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
Kubernetes Architecture | Understanding Kubernetes Components | Kubernetes Tu...
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Advanced perl finer points ,pack&unpack,eval,files
Advanced perl   finer points ,pack&unpack,eval,filesAdvanced perl   finer points ,pack&unpack,eval,files
Advanced perl finer points ,pack&unpack,eval,files
 
Basic command ppt
Basic command pptBasic command ppt
Basic command ppt
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 

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
 
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
 
05php
05php05php
05php
 

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

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
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: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
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
 
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
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 

Recently uploaded (20)

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
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
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
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
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: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
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
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
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...
 
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
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 

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