SlideShare a Scribd company logo
1 of 18
SYSTEM PROGRAMING
Software Engineering
Shell Programming…
Rahmatullah Danish
danishkakar00@gmail.com
RAHMATULLAH DANISH
1
 Introduction to Shell & shell
scripting
 Lecture 11
INTRODUCTION TO
SHELL & SHELL SCRIPTING
• If you are using any major operating system you are indirectly interaction to shell.
• If you are running any Linux distribution, you are interacting to shell every time you
use terminal.
RAHMATULLAH DANISH
2
BEFORE
UNDERSTANDING SHELL
• Kernel
• Shell
• Terminal
RAHMATULLAH DANISH
3
WHAT IS KERNEL?
• The Kernel is a computer program that is the core of computer’s operating system.
• Which complete control over everything in the system.
• It manages..
• File management
• Process management
• I/O management
• Memory management
• Device management etc…
RAHMATULLAH DANISH
4
WHAT IS SHELL?
• A shell is a special user program which provide an interface to user to use operating
system services.
• Shell accept human readable commands from user and convert them into
something which kernel can understand.
• The shell gets started when the user logs in or start the terminal.
• A bash script is a series of commands written in a file. These are read and executed
by the bash program. The program executes line by line.
RAHMATULLAH DANISH
5
WHAT IS
SHELL
Hard
ware
Kernel
Utilities
Shell
bash
csh
ksh
ls
wget
cat
ps
nano
RAHMATULLAH DANISH
6
WHAT IS SHELL
Shell is broadly classified into two categories.
• Command line shell
• Graphical shell
RAHMATULLAH DANISH
7
COMMAND LINE SHELL
• Shell can be accessed by user using a command line interface.
• A special program called Terminal in Linux/macOS or Command Prompt in
Windows OS.
• It is very powerful, it allows user to store commands in a file and execute them
together.
• These files are usually called batch files in Windows and Shell Scripts in
Linux/macOS systems.
RAHMATULLAH DANISH
8
GRAPHICAL SHELLS
• Graphical shells provide means for manipulating programs based on graphical user
interface (GUI).
• Window OS or Ubuntu OS can be considered as good example which provide GUI
to user for interacting with program.
RAHMATULLAH DANISH
9
AVAILABLE SHELL FOR
LINUX
BASH
CSH
KSH
RAHMATULLAH DANISH
10
AVAILABLE SHELL
• BASH (Bourne Again SHell) – It is most widely used shell in Linux systems. It is used
as default login shell in Linux systems and in macOS. It can also be installed on
Windows OS.
• CSH (C SHell) – The C shell’s syntax and usage are very similar to the C
programming language.
• KSH (Korn SHell) – The Korn Shell also was the base for the POSIX Shell standard
specifications etc.
RAHMATULLAH DANISH
11
SHELL SCRIPTING
• Usually shells are interactive that mean, they accept command as input from users and
execute them.
• However some time we want to execute a bunch of commands routinely, so we have type in
all commands each time in terminal.
• As shell can also take commands as input from file we can write these commands in a file
and can execute them in shell to avoid this repetitive work.
• These files are called Shell Scripts or Shell Programs.
RAHMATULLAH DANISH
12
SHELL SCRIPTING
• Each shell script is saved with .sh file extension e.g. test.sh
A shell script comprises following elements –
• Shell Keywords – if, else, break etc.
• Shell commands – cd, ls, echo, pwd, touch etc.
• Functions
• Control flow – if..then..else, case and shell loops etc.
RAHMATULLAH DANISH
13
WHY WE USE SHELL SCRIPTS
There are many reasons to write shell scripts:
• To avoid repetitive work and automation
• System admins use shell scripting for routine backups
• System monitoring
• Adding new functionality to the shell etc.
RAHMATULLAH DANISH
14
ADVANTAGES OF SHELL SCRIPTS
• The command and syntax are exactly the same as those directly entered in
command line, so programmer do not need to switch to entirely different syntax
• Writing shell scripts are much quicker
• Quick start
• Interactive debugging etc.
RAHMATULLAH DANISH
15
DISADVANTAGES OF SHELL SCRIPTS
• Prone to costly errors, a single mistake can change the command which might be
harmful
• Slow execution speed
• Design flaws within the language syntax or implementation
• Not well suited for large and complex task
• Provide minimal data structure unlike other scripting languages. etc
RAHMATULLAH DANISH
16
SYNTAX OF BASH SCRIPT
• Scripts start with a bash bang.
• Create a file test.sh
• executes rights
• Run the script
#! /bin/bash
chmod u+x test.sh
touch test.sh
./test.sh
RAHMATULLAH DANISH
17
DEFINE VARIABLES
#!/bin/bash
# A simple variable example
greeting=Hello
name=Studens
echo $greeting $name
RAHMATULLAH DANISH
18

More Related Content

Similar to Shell programing|Shel Scripting

Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Chander Pandey
 
Shell vs. Java: Overcoming the Challenges of Shell Scripting for UNIX Install...
Shell vs. Java: Overcoming the Challenges of Shell Scripting for UNIX Install...Shell vs. Java: Overcoming the Challenges of Shell Scripting for UNIX Install...
Shell vs. Java: Overcoming the Challenges of Shell Scripting for UNIX Install...Flexera
 
Shell scrpting(payal harne)
Shell scrpting(payal harne)Shell scrpting(payal harne)
Shell scrpting(payal harne)PayalHarne
 
Deepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa
 
lamp technology
lamp technologylamp technology
lamp technologyDeepa
 
Linux week 2
Linux week 2Linux week 2
Linux week 2Vinoth Sn
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction  to Command LineChapter 1: Introduction  to Command Line
Chapter 1: Introduction to Command Lineazzamhadeel89
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction to  Command LineChapter 1: Introduction to  Command Line
Chapter 1: Introduction to Command Lineazzamhadeel89
 
Linux – an introduction
Linux – an introductionLinux – an introduction
Linux – an introductionWingston
 
Shell and its types in LINUX
Shell and its types in LINUXShell and its types in LINUX
Shell and its types in LINUXSHUBHA CHATURVEDI
 
chapter-1-introduction-to-linux.ppt
chapter-1-introduction-to-linux.pptchapter-1-introduction-to-linux.ppt
chapter-1-introduction-to-linux.pptshivushivu20
 

Similar to Shell programing|Shel Scripting (20)

Presentation on rhce
Presentation on rhcePresentation on rhce
Presentation on rhce
 
UNIX/Linux training
UNIX/Linux trainingUNIX/Linux training
UNIX/Linux training
 
Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01
 
Shell vs. Java: Overcoming the Challenges of Shell Scripting for UNIX Install...
Shell vs. Java: Overcoming the Challenges of Shell Scripting for UNIX Install...Shell vs. Java: Overcoming the Challenges of Shell Scripting for UNIX Install...
Shell vs. Java: Overcoming the Challenges of Shell Scripting for UNIX Install...
 
Shell scrpting(payal harne)
Shell scrpting(payal harne)Shell scrpting(payal harne)
Shell scrpting(payal harne)
 
Deepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa ppt about lamp technology
Deepa ppt about lamp technology
 
lamp technology
lamp technologylamp technology
lamp technology
 
Linux week 2
Linux week 2Linux week 2
Linux week 2
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Linux forensics
Linux forensicsLinux forensics
Linux forensics
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction  to Command LineChapter 1: Introduction  to Command Line
Chapter 1: Introduction to Command Line
 
Chapter 1: Introduction to Command Line
Chapter 1: Introduction to  Command LineChapter 1: Introduction to  Command Line
Chapter 1: Introduction to Command Line
 
Linux basics
Linux basicsLinux basics
Linux basics
 
Linux unix-commands
Linux unix-commandsLinux unix-commands
Linux unix-commands
 
Linux – an introduction
Linux – an introductionLinux – an introduction
Linux – an introduction
 
Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02Unixshellscript 100406085942-phpapp02
Unixshellscript 100406085942-phpapp02
 
Shell Basics
Shell BasicsShell Basics
Shell Basics
 
Shell and its types in LINUX
Shell and its types in LINUXShell and its types in LINUX
Shell and its types in LINUX
 
Linux
LinuxLinux
Linux
 
chapter-1-introduction-to-linux.ppt
chapter-1-introduction-to-linux.pptchapter-1-introduction-to-linux.ppt
chapter-1-introduction-to-linux.ppt
 

Recently uploaded

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Recently uploaded (20)

Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

Shell programing|Shel Scripting

  • 1. SYSTEM PROGRAMING Software Engineering Shell Programming… Rahmatullah Danish danishkakar00@gmail.com RAHMATULLAH DANISH 1  Introduction to Shell & shell scripting  Lecture 11
  • 2. INTRODUCTION TO SHELL & SHELL SCRIPTING • If you are using any major operating system you are indirectly interaction to shell. • If you are running any Linux distribution, you are interacting to shell every time you use terminal. RAHMATULLAH DANISH 2
  • 3. BEFORE UNDERSTANDING SHELL • Kernel • Shell • Terminal RAHMATULLAH DANISH 3
  • 4. WHAT IS KERNEL? • The Kernel is a computer program that is the core of computer’s operating system. • Which complete control over everything in the system. • It manages.. • File management • Process management • I/O management • Memory management • Device management etc… RAHMATULLAH DANISH 4
  • 5. WHAT IS SHELL? • A shell is a special user program which provide an interface to user to use operating system services. • Shell accept human readable commands from user and convert them into something which kernel can understand. • The shell gets started when the user logs in or start the terminal. • A bash script is a series of commands written in a file. These are read and executed by the bash program. The program executes line by line. RAHMATULLAH DANISH 5
  • 7. WHAT IS SHELL Shell is broadly classified into two categories. • Command line shell • Graphical shell RAHMATULLAH DANISH 7
  • 8. COMMAND LINE SHELL • Shell can be accessed by user using a command line interface. • A special program called Terminal in Linux/macOS or Command Prompt in Windows OS. • It is very powerful, it allows user to store commands in a file and execute them together. • These files are usually called batch files in Windows and Shell Scripts in Linux/macOS systems. RAHMATULLAH DANISH 8
  • 9. GRAPHICAL SHELLS • Graphical shells provide means for manipulating programs based on graphical user interface (GUI). • Window OS or Ubuntu OS can be considered as good example which provide GUI to user for interacting with program. RAHMATULLAH DANISH 9
  • 11. AVAILABLE SHELL • BASH (Bourne Again SHell) – It is most widely used shell in Linux systems. It is used as default login shell in Linux systems and in macOS. It can also be installed on Windows OS. • CSH (C SHell) – The C shell’s syntax and usage are very similar to the C programming language. • KSH (Korn SHell) – The Korn Shell also was the base for the POSIX Shell standard specifications etc. RAHMATULLAH DANISH 11
  • 12. SHELL SCRIPTING • Usually shells are interactive that mean, they accept command as input from users and execute them. • However some time we want to execute a bunch of commands routinely, so we have type in all commands each time in terminal. • As shell can also take commands as input from file we can write these commands in a file and can execute them in shell to avoid this repetitive work. • These files are called Shell Scripts or Shell Programs. RAHMATULLAH DANISH 12
  • 13. SHELL SCRIPTING • Each shell script is saved with .sh file extension e.g. test.sh A shell script comprises following elements – • Shell Keywords – if, else, break etc. • Shell commands – cd, ls, echo, pwd, touch etc. • Functions • Control flow – if..then..else, case and shell loops etc. RAHMATULLAH DANISH 13
  • 14. WHY WE USE SHELL SCRIPTS There are many reasons to write shell scripts: • To avoid repetitive work and automation • System admins use shell scripting for routine backups • System monitoring • Adding new functionality to the shell etc. RAHMATULLAH DANISH 14
  • 15. ADVANTAGES OF SHELL SCRIPTS • The command and syntax are exactly the same as those directly entered in command line, so programmer do not need to switch to entirely different syntax • Writing shell scripts are much quicker • Quick start • Interactive debugging etc. RAHMATULLAH DANISH 15
  • 16. DISADVANTAGES OF SHELL SCRIPTS • Prone to costly errors, a single mistake can change the command which might be harmful • Slow execution speed • Design flaws within the language syntax or implementation • Not well suited for large and complex task • Provide minimal data structure unlike other scripting languages. etc RAHMATULLAH DANISH 16
  • 17. SYNTAX OF BASH SCRIPT • Scripts start with a bash bang. • Create a file test.sh • executes rights • Run the script #! /bin/bash chmod u+x test.sh touch test.sh ./test.sh RAHMATULLAH DANISH 17
  • 18. DEFINE VARIABLES #!/bin/bash # A simple variable example greeting=Hello name=Studens echo $greeting $name RAHMATULLAH DANISH 18