SlideShare a Scribd company logo
BASH SHELL SCRIPTING Name: Vikas Tiwari
En-roll: 14486SC029
SHELLS
A shell is the user interface or set of programs user to interact
with Unix and process commands
Common shells are:
 Bourne
 C
 Korn
BOURNE SHELL (SH)
Written by Steven Bourne of Bell Labs
Both a command interpreter and a high- level
programming language
Typically the default Unix shell
Fast
 Approximately 20 times faster than C shell because it is
similar.
C SHELL (CSH)
Written by Bill Joy at University of California at Berkeley
Slower and more complex than Bourne shell, but has
facilities to make it more user friendly
Alias
History
Job control
Filename completion
KORN SHELL (KSH)
Written by David Korn of AT&T, released in 1986
Includes features of both the Bourne and C shell
Introduces several new user interface features including
command line editing
Adds features that improve its usefulness as a programming
language
 Report formatting capabilities
 Built-in arithmetic
 Data types
SOME BASH COMMANDS
cd (change directory): change the current working directory to
‘directory’
cd… using for one step back.
SOME BASH COMMANDS
ls (list) : showing listing of the current folders
SOME BASH COMMANDS
pwd (print working directory): print name of current working
directory.
cp (copy): Create copy of files and directories
SOME BASH COMMANDS
mv (move): move from one directory place to another either
rename of the current folder/file
SOME BASH COMMANDS
less: view the contents of a text file one screen at a time.
cat: used to in display files on print screen
grep: allow you to search one file or multiple file for line that
contain a pattern
SOME BASH COMMANDS
Echo: places a string on the computer terminal.
SOME BASH COMMANDS
touch: very quick way to create new, empty files.
mkdir: make a directory.
SOME BASH COMMANDS
chmod: allow to access the permissions to the file and
directory.
SOME BASH COMMANDS
rm (remove): use in remove file, directory.
SUPERUSER
A user with essentially all privileges
 Often referred to as root privileges
Allowed access to all files
Allowed to run all commands
System administrator has superuser privileges
Can be very dangerous, all the Unix built in protections are by-
passed
PASSWORD SECURITY
Unfortunately, password security is a necessity
Good passwords have several characteristics
 Minimum of six characters
 Mixture of alpha and numeric characters
 Mixture of upper and lower case
 No real words
 Susceptible to a dictionary attack
It is also good practices to avoid:
 Family names
 Birthdates
 Pet’s names
 Any other personal data
WHAT HAPPENS WHEN YOU LOGIN?
Unix runs the login program
 If it exists, .login script is executed
Then the shell specified in /etc/passwd is executed
and user is placed in his HOME directory
 If it exists, .cshrc (if csh is your default shell) is executed
So what’s the difference? Why to initialization files?
 .login is executed only at login
 .cshrc is executed every time a new shell is spanwned
EXIT OR LOGOUT
exit terminates your current shell
If it is also your login shell, exit will exit and logout
logout terminates a login shell
SCRIPTING BASICS
Shell scripts are text files that contains a series of
commands or statements to be executed.
Shell scripts are useful for:
 Automating commonly used commands.
 Performing system administration ad troubleshooting
 Creating simple applications
 Manipulations of text or files.
 Application prototyping
CREATING SHELL SCRIPTS
Step 1: Use a text editor such as vi to create a text file
containg commands.
 First line contains the magic “shbang” sequence :#!
 #!/bin/bash
 Comments your scripts
 Comments start with a#
Create shell scripts which is self documenting.
If you this pressing  key followed by the Enter key on
the most keyboards. This will enable you to enter one
command that spans multiple lines.
CREATING SHELL SCRIPTS CONT.
Step 2: Make the script executable
$ chmod a+x myscript.sh
To execute the new scripts:
Place the scripts file in a directory in the executable
path –OR-
Specify the absolute path or relative path to the script
on the command line.
CONTROL STRUCTURES
The three types in shell programming:
Sequential structures – the program flows one
line after another
Selection structures – code execution based on
a logical decision.
 if, if/else, if/elif/else and conditional operators.
Repetition structures (loos) –code execution is
repeated based on a logical decision
 for, while and until
CONDITIONAL EXECUTION
Commands may be executed conditionally, based on
the exit states of the previous command.
 && logical AND
 || logical OR
Examples:
 $ grep vikas passwd || echo ‘No vikas!’
 $cp –a /tmp/*.o . && echo ‘Done!’
This structures can be used in the command line as
well.
SELECTION STRUCTURES:
IF/THEN/ELIF
if selection structures execute the body of the
structure only if the condition tested is true.
if condition
then
 statement1
 statement2
 ………………..
fi
SELECTION STRUCTURES:
IF/THEN/ELIF CONT.
Sometimes, you may wish to specify an alternate
action when the condition fails. Here's how it's done.
 if condition
 then
 statement1
 statement2
 ………………..
 else
 statement3
 fi
SELECTION STRUCTURES:
IF/THEN/ELIF CONT.
alternatively, it is possible to test for another condition if the first "if" fails.
 if condition1
 then
 statement1
 statement2
 …………………
 elif condition2
 then
 statement3
 statement4
 …………………
 elif condition3
 then
 statement5
 statement6
 …………………
 fi
REPETITION STRUCTURES: THE
FOR-LOOP
The for repetition structure provides a method for iterating, or
looping, through a list of values and executing commands on
each of these values.
A loop requires
a) Start point
Process/Logic/statements to be repeated
b) Some hint or condition which changed the initial condition which
started the loop
c) Termination condition
 for variable in list-of-values
 do
 commands …
 done
SELECTION STRUCTURES: THE
WHILE-LOOP
The while loop structure provides a useful method for
performing a set of commands while a condition remains true.
The syntax is:
 while condition
 do
 commands
 Done
While loops are known as sentinel structures.
An until loop works in exactly the same way, except that it
continues to execute as long as the command following the
until statement executes successfully; that is it will stop the
loop when the command succeeds.
Thank You!

More Related Content

PPTX
Linux basics
Shagun Rathore
 
PPTX
Linux fundamentals
Raghu nath
 
PDF
Shell scripting
Geeks Anonymes
 
PPTX
Introduction to linux
Stephen Ahiante
 
PPTX
SHELL PROGRAMMING
jinal thakrar
 
PPTX
File permission in linux
Prakash Poudel
 
PPTX
Shell scripting
simha.dev.lin
 
Linux basics
Shagun Rathore
 
Linux fundamentals
Raghu nath
 
Shell scripting
Geeks Anonymes
 
Introduction to linux
Stephen Ahiante
 
SHELL PROGRAMMING
jinal thakrar
 
File permission in linux
Prakash Poudel
 
Shell scripting
simha.dev.lin
 

What's hot (20)

PPT
Linux command ppt
kalyanineve
 
PDF
Linux introduction
Md. Zahid Hossain Shoeb
 
PDF
Shell scripting
Manav Prasad
 
PPT
Basic Linux Internals
mukul bhardwaj
 
PDF
Linux basic commands with examples
abclearnn
 
PDF
Linux systems - Linux Commands and Shell Scripting
Emertxe Information Technologies Pvt Ltd
 
PPT
Shell Scripting
Gaurav Shinde
 
PPTX
Linux.ppt
onu9
 
PPTX
Linux file system
Md. Tanvir Hossain
 
PPTX
Filepermissions in linux
Subashini Pandiarajan
 
PDF
Complete Guide for Linux shell programming
sudhir singh yadav
 
ODP
Introduction to Shell script
Bhavesh Padharia
 
PPT
Shell programming
Moayad Moawiah
 
PPT
Linux presentation
Nikhil Jain
 
PPTX
Unix ppt
sudhir saurav
 
PPT
Server configuration
Aisha Talat
 
PPTX
Linux commands
Mannu Khani
 
PPT
Linux basics
Santosh Khadsare
 
PPT
Linux - Introductions to Linux Operating System
Vibrant Technologies & Computers
 
Linux command ppt
kalyanineve
 
Linux introduction
Md. Zahid Hossain Shoeb
 
Shell scripting
Manav Prasad
 
Basic Linux Internals
mukul bhardwaj
 
Linux basic commands with examples
abclearnn
 
Linux systems - Linux Commands and Shell Scripting
Emertxe Information Technologies Pvt Ltd
 
Shell Scripting
Gaurav Shinde
 
Linux.ppt
onu9
 
Linux file system
Md. Tanvir Hossain
 
Filepermissions in linux
Subashini Pandiarajan
 
Complete Guide for Linux shell programming
sudhir singh yadav
 
Introduction to Shell script
Bhavesh Padharia
 
Shell programming
Moayad Moawiah
 
Linux presentation
Nikhil Jain
 
Unix ppt
sudhir saurav
 
Server configuration
Aisha Talat
 
Linux commands
Mannu Khani
 
Linux basics
Santosh Khadsare
 
Linux - Introductions to Linux Operating System
Vibrant Technologies & Computers
 
Ad

Viewers also liked (20)

PPTX
Bash Shell Scripting
Raghu nath
 
PDF
Unix Shell Script
student
 
PDF
Unix Shell Scripting
Mustafa Qasim
 
PDF
Intro to Linux Shell Scripting
vceder
 
PPT
Unix Shell Scripting Basics
Dr.Ravi
 
PPT
Shell Scripting in Linux
Anu Chaudhry
 
PPT
Unix And Shell Scripting
Jaibeer Malik
 
ODP
OpenGurukul : Language : Shell Scripting
Open Gurukul
 
PPTX
Licão 11 decision making - statement
Acácio Oliveira
 
PDF
Bash scripting for beginner and intermediate
Ahmed Gamil
 
PDF
Shell scripting
Ashrith Mekala
 
PDF
Quick start bash script
Simon Su
 
PDF
Shell script
Tiago
 
PPTX
Linux Shell Basics
Constantine Nosovsky
 
PPTX
Easiest way to start with Shell scripting
Akshay Siwal
 
PDF
Linux Bash Shell Cheat Sheet for Beginners
Davide Ciambelli
 
PDF
Unixshellscript 100406085942-phpapp02
Ben Mohammed Esskhayri
 
PDF
Linux Shell Scripting Craftsmanship
bokonen
 
PPS
UNIX - Class1 - Basic Shell
Nihar Ranjan Paital
 
PDF
Trouble shoot with linux syslog
ashok191
 
Bash Shell Scripting
Raghu nath
 
Unix Shell Script
student
 
Unix Shell Scripting
Mustafa Qasim
 
Intro to Linux Shell Scripting
vceder
 
Unix Shell Scripting Basics
Dr.Ravi
 
Shell Scripting in Linux
Anu Chaudhry
 
Unix And Shell Scripting
Jaibeer Malik
 
OpenGurukul : Language : Shell Scripting
Open Gurukul
 
Licão 11 decision making - statement
Acácio Oliveira
 
Bash scripting for beginner and intermediate
Ahmed Gamil
 
Shell scripting
Ashrith Mekala
 
Quick start bash script
Simon Su
 
Shell script
Tiago
 
Linux Shell Basics
Constantine Nosovsky
 
Easiest way to start with Shell scripting
Akshay Siwal
 
Linux Bash Shell Cheat Sheet for Beginners
Davide Ciambelli
 
Unixshellscript 100406085942-phpapp02
Ben Mohammed Esskhayri
 
Linux Shell Scripting Craftsmanship
bokonen
 
UNIX - Class1 - Basic Shell
Nihar Ranjan Paital
 
Trouble shoot with linux syslog
ashok191
 
Ad

Similar to Bash shell scripting (20)

PDF
Shell scripting1232232312312312312312312
adnansalam11
 
PDF
Shell-Scripting-1.pdf
aznabi
 
PPTX
Shell & Shell Script
Amit Ghosh
 
PPTX
Shell & Shell Script
Amit Ghosh
 
PDF
Shell Scripting crash course.pdf
harikrishnapolaki
 
DOCX
What is a shell script
Dr.M.Karthika parthasarathy
 
PPT
34-shell-programming asda asda asd asd.ppt
poyotero
 
PDF
Unix shell scripting tutorial
Prof. Dr. K. Adisesha
 
PPTX
Shell scripting
Mufaddal Haidermota
 
PDF
Shell Programming_Module2_Part2.pptx.pdf
HIMANKMISHRA2
 
PPT
34-shell-programming.ppt
KiranMantri
 
PPT
Unix shell scripting basics
Abhay Sapru
 
PPT
ShellProgramming and Script in operating system
vinitasharma749430
 
PPT
1 4 sp
Bhargavi Bbv
 
PPTX
Licão 02 shell basics bash intro
Acácio Oliveira
 
PDF
Module 03 Programming on Linux
Tushar B Kute
 
PPT
2-introduction_to_shell_scripting
erbipulkumar
 
PPT
Introduction to shell scripting ____.ppt
nalinisamineni
 
Shell scripting1232232312312312312312312
adnansalam11
 
Shell-Scripting-1.pdf
aznabi
 
Shell & Shell Script
Amit Ghosh
 
Shell & Shell Script
Amit Ghosh
 
Shell Scripting crash course.pdf
harikrishnapolaki
 
What is a shell script
Dr.M.Karthika parthasarathy
 
34-shell-programming asda asda asd asd.ppt
poyotero
 
Unix shell scripting tutorial
Prof. Dr. K. Adisesha
 
Shell scripting
Mufaddal Haidermota
 
Shell Programming_Module2_Part2.pptx.pdf
HIMANKMISHRA2
 
34-shell-programming.ppt
KiranMantri
 
Unix shell scripting basics
Abhay Sapru
 
ShellProgramming and Script in operating system
vinitasharma749430
 
1 4 sp
Bhargavi Bbv
 
Licão 02 shell basics bash intro
Acácio Oliveira
 
Module 03 Programming on Linux
Tushar B Kute
 
2-introduction_to_shell_scripting
erbipulkumar
 
Introduction to shell scripting ____.ppt
nalinisamineni
 

Recently uploaded (20)

PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PDF
Structs to JSON How Go Powers REST APIs.pdf
Emily Achieng
 
PDF
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
PDF
Queuing formulas to evaluate throughputs and servers
gptshubham
 
PPTX
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
PDF
6th International Conference on Artificial Intelligence and Machine Learning ...
gerogepatton
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
PDF
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
PDF
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
PPTX
Edge to Cloud Protocol HTTP WEBSOCKET MQTT-SN MQTT.pptx
dhanashri894551
 
PPT
High Data Link Control Protocol in Data Link Layer
shailajacse
 
PPTX
Simulation of electric circuit laws using tinkercad.pptx
VidhyaH3
 
PPTX
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
dodultrongaming
 
PDF
ETO & MEO Certificate of Competency Questions and Answers
Mahmoud Moghtaderi
 
PDF
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Ajaykumar966781
 
PDF
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Dr. Rahul Kumar
 
PPTX
Azure-DevOps-Training presentation downloadable
NamanGoyal428595
 
PDF
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Structs to JSON How Go Powers REST APIs.pdf
Emily Achieng
 
Principles of Food Science and Nutritions
Dr. Yogesh Kumar Kosariya
 
Queuing formulas to evaluate throughputs and servers
gptshubham
 
AgentX UiPath Community Webinar series - Delhi
RohitRadhakrishnan8
 
6th International Conference on Artificial Intelligence and Machine Learning ...
gerogepatton
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Chad Ayach - A Versatile Aerospace Professional
Chad Ayach
 
오픈소스 LLM, vLLM으로 Production까지 (Instruct.KR Summer Meetup, 2025)
Hyogeun Oh
 
Edge to Cloud Protocol HTTP WEBSOCKET MQTT-SN MQTT.pptx
dhanashri894551
 
High Data Link Control Protocol in Data Link Layer
shailajacse
 
Simulation of electric circuit laws using tinkercad.pptx
VidhyaH3
 
ANIMAL INTERVENTION WARNING SYSTEM (4).pptx
dodultrongaming
 
ETO & MEO Certificate of Competency Questions and Answers
Mahmoud Moghtaderi
 
algorithms-16-00088-v2hghjjnjnhhhnnjhj.pdf
Ajaykumar966781
 
July 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Dr. Rahul Kumar
 
Azure-DevOps-Training presentation downloadable
NamanGoyal428595
 
dse_final_merit_2025_26 gtgfffffcjjjuuyy
rushabhjain127
 

Bash shell scripting

  • 1. BASH SHELL SCRIPTING Name: Vikas Tiwari En-roll: 14486SC029
  • 2. SHELLS A shell is the user interface or set of programs user to interact with Unix and process commands Common shells are:  Bourne  C  Korn
  • 3. BOURNE SHELL (SH) Written by Steven Bourne of Bell Labs Both a command interpreter and a high- level programming language Typically the default Unix shell Fast  Approximately 20 times faster than C shell because it is similar.
  • 4. C SHELL (CSH) Written by Bill Joy at University of California at Berkeley Slower and more complex than Bourne shell, but has facilities to make it more user friendly Alias History Job control Filename completion
  • 5. KORN SHELL (KSH) Written by David Korn of AT&T, released in 1986 Includes features of both the Bourne and C shell Introduces several new user interface features including command line editing Adds features that improve its usefulness as a programming language  Report formatting capabilities  Built-in arithmetic  Data types
  • 6. SOME BASH COMMANDS cd (change directory): change the current working directory to ‘directory’ cd… using for one step back.
  • 7. SOME BASH COMMANDS ls (list) : showing listing of the current folders
  • 8. SOME BASH COMMANDS pwd (print working directory): print name of current working directory. cp (copy): Create copy of files and directories
  • 9. SOME BASH COMMANDS mv (move): move from one directory place to another either rename of the current folder/file
  • 10. SOME BASH COMMANDS less: view the contents of a text file one screen at a time. cat: used to in display files on print screen grep: allow you to search one file or multiple file for line that contain a pattern
  • 11. SOME BASH COMMANDS Echo: places a string on the computer terminal.
  • 12. SOME BASH COMMANDS touch: very quick way to create new, empty files. mkdir: make a directory.
  • 13. SOME BASH COMMANDS chmod: allow to access the permissions to the file and directory.
  • 14. SOME BASH COMMANDS rm (remove): use in remove file, directory.
  • 15. SUPERUSER A user with essentially all privileges  Often referred to as root privileges Allowed access to all files Allowed to run all commands System administrator has superuser privileges Can be very dangerous, all the Unix built in protections are by- passed
  • 16. PASSWORD SECURITY Unfortunately, password security is a necessity Good passwords have several characteristics  Minimum of six characters  Mixture of alpha and numeric characters  Mixture of upper and lower case  No real words  Susceptible to a dictionary attack It is also good practices to avoid:  Family names  Birthdates  Pet’s names  Any other personal data
  • 17. WHAT HAPPENS WHEN YOU LOGIN? Unix runs the login program  If it exists, .login script is executed Then the shell specified in /etc/passwd is executed and user is placed in his HOME directory  If it exists, .cshrc (if csh is your default shell) is executed So what’s the difference? Why to initialization files?  .login is executed only at login  .cshrc is executed every time a new shell is spanwned
  • 18. EXIT OR LOGOUT exit terminates your current shell If it is also your login shell, exit will exit and logout logout terminates a login shell
  • 19. SCRIPTING BASICS Shell scripts are text files that contains a series of commands or statements to be executed. Shell scripts are useful for:  Automating commonly used commands.  Performing system administration ad troubleshooting  Creating simple applications  Manipulations of text or files.  Application prototyping
  • 20. CREATING SHELL SCRIPTS Step 1: Use a text editor such as vi to create a text file containg commands.  First line contains the magic “shbang” sequence :#!  #!/bin/bash  Comments your scripts  Comments start with a# Create shell scripts which is self documenting. If you this pressing key followed by the Enter key on the most keyboards. This will enable you to enter one command that spans multiple lines.
  • 21. CREATING SHELL SCRIPTS CONT. Step 2: Make the script executable $ chmod a+x myscript.sh To execute the new scripts: Place the scripts file in a directory in the executable path –OR- Specify the absolute path or relative path to the script on the command line.
  • 22. CONTROL STRUCTURES The three types in shell programming: Sequential structures – the program flows one line after another Selection structures – code execution based on a logical decision.  if, if/else, if/elif/else and conditional operators. Repetition structures (loos) –code execution is repeated based on a logical decision  for, while and until
  • 23. CONDITIONAL EXECUTION Commands may be executed conditionally, based on the exit states of the previous command.  && logical AND  || logical OR Examples:  $ grep vikas passwd || echo ‘No vikas!’  $cp –a /tmp/*.o . && echo ‘Done!’ This structures can be used in the command line as well.
  • 24. SELECTION STRUCTURES: IF/THEN/ELIF if selection structures execute the body of the structure only if the condition tested is true. if condition then  statement1  statement2  ……………….. fi
  • 25. SELECTION STRUCTURES: IF/THEN/ELIF CONT. Sometimes, you may wish to specify an alternate action when the condition fails. Here's how it's done.  if condition  then  statement1  statement2  ………………..  else  statement3  fi
  • 26. SELECTION STRUCTURES: IF/THEN/ELIF CONT. alternatively, it is possible to test for another condition if the first "if" fails.  if condition1  then  statement1  statement2  …………………  elif condition2  then  statement3  statement4  …………………  elif condition3  then  statement5  statement6  …………………  fi
  • 27. REPETITION STRUCTURES: THE FOR-LOOP The for repetition structure provides a method for iterating, or looping, through a list of values and executing commands on each of these values. A loop requires a) Start point Process/Logic/statements to be repeated b) Some hint or condition which changed the initial condition which started the loop c) Termination condition  for variable in list-of-values  do  commands …  done
  • 28. SELECTION STRUCTURES: THE WHILE-LOOP The while loop structure provides a useful method for performing a set of commands while a condition remains true. The syntax is:  while condition  do  commands  Done While loops are known as sentinel structures. An until loop works in exactly the same way, except that it continues to execute as long as the command following the until statement executes successfully; that is it will stop the loop when the command succeeds.