SlideShare a Scribd company logo
1 of 24
Shell Scripting
Introduction Of Shell Scripting
Shell Scripting
● If you are using any major operating system you are indirectly interacting to
shell.
● If you are running Ubuntu, Linux Mint or any other Linux distribution, you
are interacting to shell every time you use terminal.
● Let’s discuss about linux shells and shell scripting so before understanding
shell scripting we have to get familiar with following terminologies –
● Kernel
● Shell
● Terminal
Shell Scripting
● What is Kernel?
● The kernel is a computer program that is the core of a computer’s operating system,
with complete control over everything in the system.
● It manages following resources of the Linux system –
● File management
● Process management
● I/O management
● Memory management
● Device management etc.
Shell Scripting
● It is often mistaken that Linus Torvalds has developed
Linux OS, but actually he is only responsible for
development of Linux kernel.
● Complete Linux system = Kernel + GNU system utilities
and libraries + other management scripts + installation.
Scripts.
Shell Scripting
● A shell is 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.
● It is a command language interpreter that execute
commands read from input devices such as keyboards or
from files.
● The shell gets started when the user logs in or start the
terminal.
Shell Scripting
● Shell is broadly classified into two categories –
● Command Line Shell
● Graphical shell
Shell Scripting
● 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 is provided to type in
the human readable commands such as “cat”, “ls” etc. and
then it is being execute.
● The result is then displayed on the terminal to the user. A
terminal in Ubuntu 16.4 system looks like this –
Shell Scripting
Shell Scripting
● Graphical Shells
Graphical shells provide means for manipulating programs
based on graphical user interface (GUI), by allowing for
operations.
● Such as opening, closing, moving and resizing windows, as well
as switching focus between windows.
● Window OS or Ubuntu OS can be considered as good example
which provide GUI to user for interacting with program. User do
not need to type in command for every actions.A typical GUI in
Ubuntu system –
Shell Scripting
Shell Scripting
● There are several shells are available for Linux systems
like –
● BASH (Bourne Again SHell)
● CSH (C Shell)
● KSH (Korn SHell)
Shell Scripting
● 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.
Shell Scripting
● CSH (C SHell) –
● The C shell’s syntax and usage are very similar to the C
programming language.
Shell Scripting
● KSH (Korn SHell) –
● The Korn Shell also was the base for the POSIX Shell
standard specifications etc.
● Each shell does the same job but understand different
commands and provide different built in functions.
Shell Scripting
● 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.
Shell Scripting
● 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. Shell scripts
are similar to the batch file in MS-DOS.
● Each shell script is saved with .sh file extension eg. myscript.sh
● A shell script have syntax just like any other programming language.
● If you have any prior experience with any programming language like
Python, C/C++ etc. it would be very easy to get started with it.
Shell Scripting
● 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.
Shell Scripting
● Why do we need 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.
Shell Scripting
● 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.
Shell Scripting
● 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
Shell Scripting
● Command in Shell Scripting :
● Ls – The ls comand : The list command function in the linux terminal
to show all of the major directories filed under a given file system.
● Cd – The cd command : Change directory will allow the user to
change between file directories.
● Mv – The mv command : Move allow a user to move a file to another
folder.
● Mkdir – The mkdir command : Make directory command allows the
user to make a new directory.
Shell Scripting
● Man – The man command : The manual command is
used to show the manual of the inputted command.
● Touch – The touch command to make file in the directory.
● Rm – The rm command : The rmdir to remove the file and
directory in the linux OS.
● Clear – The clear command : The clear command does
exactly what it say clear. It clear all readout and
information from the screen.
Shell Scripting
● Example of Shell Scripting :
● 1. For our first shell script , we will write a script which say “Hello World”.
● Input :
●
 #!/bin/sh
●
# This is a comment!
● echo Hello World # This is a comment, too!
● Output :
● Hello World
●
Shell Scripting
Thank you

More Related Content

What's hot

Linux command ppt
Linux command pptLinux command ppt
Linux command pptkalyanineve
 
Bash shell
Bash shellBash shell
Bash shellxylas121
 
Shell and its types in LINUX
Shell and its types in LINUXShell and its types in LINUX
Shell and its types in LINUXSHUBHA CHATURVEDI
 
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
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utilityNirajan Pant
 
Linux architecture
Linux architectureLinux architecture
Linux architecturemcganesh
 
Linux Administration
Linux AdministrationLinux Administration
Linux AdministrationHarish1983
 
Linux ppt
Linux pptLinux ppt
Linux pptlincy21
 
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 scriptingAkshay Siwal
 
Linux Networking Commands
Linux Networking CommandsLinux Networking Commands
Linux Networking Commandstmavroidis
 
Linux Directory Structure
Linux Directory StructureLinux Directory Structure
Linux Directory StructureKevin OBrien
 
Linux process management
Linux process managementLinux process management
Linux process managementRaghu nath
 

What's hot (20)

Linux command ppt
Linux command pptLinux command ppt
Linux command ppt
 
System calls
System callsSystem calls
System calls
 
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
Bash shellBash shell
Bash shell
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell and its types in LINUX
Shell and its types in LINUXShell and its types in LINUX
Shell and its types in LINUX
 
Linux commands
Linux commandsLinux commands
Linux commands
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Operating Systems
Operating SystemsOperating Systems
Operating Systems
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 
Linux ppt
Linux pptLinux ppt
Linux ppt
 
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
 
Linux Networking Commands
Linux Networking CommandsLinux Networking Commands
Linux Networking Commands
 
Linux Directory Structure
Linux Directory StructureLinux Directory Structure
Linux Directory Structure
 
Linux
LinuxLinux
Linux
 
Introduction to Unix
Introduction to UnixIntroduction to Unix
Introduction to Unix
 
Basic 50 linus command
Basic 50 linus commandBasic 50 linus command
Basic 50 linus command
 
Linux process management
Linux process managementLinux process management
Linux process management
 

Similar to Introduction to Shell Scripting

Shell programing|Shel Scripting
Shell programing|Shel ScriptingShell programing|Shel Scripting
Shell programing|Shel ScriptingDaNish KaKar
 
Tips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyTips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyOlivier Bourgeois
 
The Shell Game Part 1: What is a shell?
The Shell Game Part 1: What is a shell?The Shell Game Part 1: What is a shell?
The Shell Game Part 1: What is a shell?Kevin OBrien
 
Linux week 2
Linux week 2Linux week 2
Linux week 2Vinoth Sn
 
Linux administration training
Linux administration trainingLinux administration training
Linux administration trainingiman darabi
 
Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Chander Pandey
 
shell-programming.ppt
shell-programming.pptshell-programming.ppt
shell-programming.pptchetan818271
 

Similar to Introduction to Shell Scripting (20)

Linux Systems: Getting started with setting up an Embedded platform
Linux Systems: Getting started with setting up an Embedded platformLinux Systems: Getting started with setting up an Embedded platform
Linux Systems: Getting started with setting up an Embedded platform
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Linux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platformLinux systems - Getting started with setting up and embedded platform
Linux systems - Getting started with setting up and embedded platform
 
Shell programing|Shel Scripting
Shell programing|Shel ScriptingShell programing|Shel Scripting
Shell programing|Shel Scripting
 
Tips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyTips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development Efficiency
 
Introduction to Linux
Introduction to LinuxIntroduction to Linux
Introduction to Linux
 
Linux
LinuxLinux
Linux
 
UNIX/Linux training
UNIX/Linux trainingUNIX/Linux training
UNIX/Linux training
 
Command Line Interpreter
Command Line InterpreterCommand Line Interpreter
Command Line Interpreter
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
The Shell Game Part 1: What is a shell?
The Shell Game Part 1: What is a shell?The Shell Game Part 1: What is a shell?
The Shell Game Part 1: What is a shell?
 
60761 linux
60761 linux60761 linux
60761 linux
 
Linux week 2
Linux week 2Linux week 2
Linux week 2
 
Before begining linux
Before begining linuxBefore begining linux
Before begining linux
 
Linux administration training
Linux administration trainingLinux administration training
Linux administration training
 
Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01Linuxtraining 130710022121-phpapp01
Linuxtraining 130710022121-phpapp01
 
Linux unix-commands
Linux unix-commandsLinux unix-commands
Linux unix-commands
 
Linux basic
Linux basicLinux basic
Linux basic
 
shell-programming.ppt
shell-programming.pptshell-programming.ppt
shell-programming.ppt
 
Unix final
Unix finalUnix final
Unix final
 

Recently uploaded

Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfMarinCaroMartnezBerg
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Jack DiGiovanna
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...Suhani Kapoor
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxJohnnyPlasten
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts ServiceSapana Sha
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一ffjhghh
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...shivangimorya083
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 

Recently uploaded (20)

Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
FESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdfFESE Capital Markets Fact Sheet 2024 Q1.pdf
FESE Capital Markets Fact Sheet 2024 Q1.pdf
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
VIP High Profile Call Girls Amravati Aarushi 8250192130 Independent Escort Se...
 
Log Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptxLog Analysis using OSSEC sasoasasasas.pptx
Log Analysis using OSSEC sasoasasasas.pptx
 
Call Girls In Mahipalpur O9654467111 Escorts Service
Call Girls In Mahipalpur O9654467111  Escorts ServiceCall Girls In Mahipalpur O9654467111  Escorts Service
Call Girls In Mahipalpur O9654467111 Escorts Service
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
 
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
Full night 🥵 Call Girls Delhi New Friends Colony {9711199171} Sanya Reddy ✌️o...
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 

Introduction to Shell Scripting

  • 2. Shell Scripting ● If you are using any major operating system you are indirectly interacting to shell. ● If you are running Ubuntu, Linux Mint or any other Linux distribution, you are interacting to shell every time you use terminal. ● Let’s discuss about linux shells and shell scripting so before understanding shell scripting we have to get familiar with following terminologies – ● Kernel ● Shell ● Terminal
  • 3. Shell Scripting ● What is Kernel? ● The kernel is a computer program that is the core of a computer’s operating system, with complete control over everything in the system. ● It manages following resources of the Linux system – ● File management ● Process management ● I/O management ● Memory management ● Device management etc.
  • 4. Shell Scripting ● It is often mistaken that Linus Torvalds has developed Linux OS, but actually he is only responsible for development of Linux kernel. ● Complete Linux system = Kernel + GNU system utilities and libraries + other management scripts + installation. Scripts.
  • 5. Shell Scripting ● A shell is 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. ● It is a command language interpreter that execute commands read from input devices such as keyboards or from files. ● The shell gets started when the user logs in or start the terminal.
  • 6. Shell Scripting ● Shell is broadly classified into two categories – ● Command Line Shell ● Graphical shell
  • 7. Shell Scripting ● 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 is provided to type in the human readable commands such as “cat”, “ls” etc. and then it is being execute. ● The result is then displayed on the terminal to the user. A terminal in Ubuntu 16.4 system looks like this –
  • 9. Shell Scripting ● Graphical Shells Graphical shells provide means for manipulating programs based on graphical user interface (GUI), by allowing for operations. ● Such as opening, closing, moving and resizing windows, as well as switching focus between windows. ● Window OS or Ubuntu OS can be considered as good example which provide GUI to user for interacting with program. User do not need to type in command for every actions.A typical GUI in Ubuntu system –
  • 11. Shell Scripting ● There are several shells are available for Linux systems like – ● BASH (Bourne Again SHell) ● CSH (C Shell) ● KSH (Korn SHell)
  • 12. Shell Scripting ● 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.
  • 13. Shell Scripting ● CSH (C SHell) – ● The C shell’s syntax and usage are very similar to the C programming language.
  • 14. Shell Scripting ● KSH (Korn SHell) – ● The Korn Shell also was the base for the POSIX Shell standard specifications etc. ● Each shell does the same job but understand different commands and provide different built in functions.
  • 15. Shell Scripting ● 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.
  • 16. Shell Scripting ● 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. Shell scripts are similar to the batch file in MS-DOS. ● Each shell script is saved with .sh file extension eg. myscript.sh ● A shell script have syntax just like any other programming language. ● If you have any prior experience with any programming language like Python, C/C++ etc. it would be very easy to get started with it.
  • 17. Shell Scripting ● 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.
  • 18. Shell Scripting ● Why do we need 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.
  • 19. Shell Scripting ● 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.
  • 20. Shell Scripting ● 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
  • 21. Shell Scripting ● Command in Shell Scripting : ● Ls – The ls comand : The list command function in the linux terminal to show all of the major directories filed under a given file system. ● Cd – The cd command : Change directory will allow the user to change between file directories. ● Mv – The mv command : Move allow a user to move a file to another folder. ● Mkdir – The mkdir command : Make directory command allows the user to make a new directory.
  • 22. Shell Scripting ● Man – The man command : The manual command is used to show the manual of the inputted command. ● Touch – The touch command to make file in the directory. ● Rm – The rm command : The rmdir to remove the file and directory in the linux OS. ● Clear – The clear command : The clear command does exactly what it say clear. It clear all readout and information from the screen.
  • 23. Shell Scripting ● Example of Shell Scripting : ● 1. For our first shell script , we will write a script which say “Hello World”. ● Input : ●  #!/bin/sh ● # This is a comment! ● echo Hello World # This is a comment, too! ● Output : ● Hello World ●