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
 
lamp technology
lamp technologylamp technology
lamp technologyDeepa
 
Deepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa ppt about lamp technology
Deepa ppt about 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)
 
lamp technology
lamp technologylamp technology
lamp technology
 
Deepa ppt about lamp technology
Deepa ppt about lamp technologyDeepa ppt about lamp technology
Deepa ppt about 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

Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaVirag Sontakke
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitolTechU
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfadityarao40181
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementmkooblal
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfSumit Tiwari
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Recently uploaded (20)

Painted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of IndiaPainted Grey Ware.pptx, PGW Culture of India
Painted Grey Ware.pptx, PGW Culture of India
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Capitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptxCapitol Tech U Doctoral Presentation - April 2024.pptx
Capitol Tech U Doctoral Presentation - April 2024.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Biting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdfBiting mechanism of poisonous snakes.pdf
Biting mechanism of poisonous snakes.pdf
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Hierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of managementHierarchy of management that covers different levels of management
Hierarchy of management that covers different levels of management
 
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdfEnzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
Enzyme, Pharmaceutical Aids, Miscellaneous Last Part of Chapter no 5th.pdf
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 

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