SlideShare a Scribd company logo
Handling Repetition
Presentation Subtitle
2
What is Handling Repetition ?
Handling Repetition is control structure also known as looping control structure,Handling Repetition is control structure also known as looping control structure,
is a type of control structure in programming languages that is used to simplify repetitive oris a type of control structure in programming languages that is used to simplify repetitive or
recursive tasks operation.recursive tasks operation.
Delete zero sized files in system.Delete zero sized files in system.
3
Code for write a script to delete zero sized files from a given directory
(and all its subdirectories) in Unix / Linux / Ubuntu
Code for write a script to delete zero sized files from a given directory
(and all its subdirectories) in Unix / Linux / Ubuntu
4
5
Script 19
Handling Repetition is control structure also known as looping control structure,Handling Repetition is control structure also known as looping control structure,
is a type of control structure in programming languages that is used to simplify repetitive oris a type of control structure in programming languages that is used to simplify repetitive or
recursive tasks operation.recursive tasks operation.
6
Repetitive tasks
1.1. The for loopThe for loop
2.2. The while loopThe while loop
3.3. The until loopThe until loop
7
The for loopThe for loop
The for loop is the first of the three shell looping constructs.
This loop allows for specification of a list of values.
A list of commands is executed for each value in the list.
8
for loop Syntaxfor loop Syntax
9
for loop Examplefor loop Example
$ cat for1.sh
i=1
for day in Mon Tue Wed Thu Fri
do
echo "Weekday $((i++)) : $day"
done
$ ./for1.sh
Weekday 1 : Mon
Weekday 2 : Tue
Weekday 3 : Wed
Weekday 4 : Thu
Weekday 5 : Fri
10
The while loopThe while loop
The while construct allows for repetitive execution of a list of commands, as long as the
command controlling the while loop executes successfully (exit status of zero)
The while construct allows for repetitive execution of a list of commands, as long as the
command controlling the while loop executes successfully (exit status of zero)
11
The while loopThe while loop
12
while loop Syntaxwhile loop Syntax
13
while loop Examplewhile loop Example
a=0
while [ $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
14
The until loopThe until loop
15
until loop Syntaxuntil loop Syntax
until <TEST-COMMAND>;
do
CONSEQUENT - COMMANDS;
done
16
until loop Exampleuntil loop Example
until [ $DISKFUL -ge "90" ];
do
DATE=`date +%Y%m%d`
HOUR=`date +%H`
mkdir $WEBDIR/"$DATE"
while [ $HOUR -ne "00" ];
do
DESTDIR=$WEBDIR/"$DATE"/"$HOUR"
mkdir "$DESTDIR" mv $PICDIR/*.jpg "$DESTDIR"/
sleep 3600 HOUR=`date +%H`
done
Functions in script
18
What is Function ?
A function is a subroutine, a code block that implements a set of operations, a "black
box" that performs a specified task. Wherever there is repetitive code, when a task repeats
with only slight variations in procedure, then consider using a function.
19
Syntax of Function ?
function function_name {
command...
}
or
function_name () {
command...
}
20
Example of Function ?
21
Example of Function ?
22
23
24
25
26
27
28
29
30
31
32

More Related Content

What's hot (20)

PDF
Go for Rubyists
Luka Zakrajšek
 
DOCX
lec4.docx
ismailaboshatra
 
PDF
Let's Go-lang
Luka Zakrajšek
 
PDF
Proces
samof76
 
PPTX
Bash script (mask off remix)
Elaine Yeung
 
PDF
Using the command line on macOS
AdamFallon4
 
PDF
Emscripten, asm.js, and billions of math ops
Luka Zakrajšek
 
PDF
Defer, Panic, Recover
Joris Bonnefoy
 
TXT
Forkexpe
Karthic Rao
 
TXT
Sender
nikhil jasani
 
PPT
Unix Programming with Perl 2
Kazuho Oku
 
PDF
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
Jan Stamer
 
PDF
3 rd animation
divyalakshmi77
 
ODP
Rust言語紹介
Paweł Rusin
 
PPTX
Hebrew Windows Cluster 2012 in a one slide diagram
G M
 
PDF
Mashup your life with Yahoo Pipes
Cristiano Betta
 
TXT
Unix2
Krishna Prasad
 
PDF
betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
Jan Stamer
 
DOCX
Note
Posoffaith1
 
PPT
Unix Programming with Perl
Kazuho Oku
 
Go for Rubyists
Luka Zakrajšek
 
lec4.docx
ismailaboshatra
 
Let's Go-lang
Luka Zakrajšek
 
Proces
samof76
 
Bash script (mask off remix)
Elaine Yeung
 
Using the command line on macOS
AdamFallon4
 
Emscripten, asm.js, and billions of math ops
Luka Zakrajšek
 
Defer, Panic, Recover
Joris Bonnefoy
 
Forkexpe
Karthic Rao
 
Unix Programming with Perl 2
Kazuho Oku
 
JavaForum Nord 2021: Java to Go - Google Go für Java-Entwickler
Jan Stamer
 
3 rd animation
divyalakshmi77
 
Rust言語紹介
Paweł Rusin
 
Hebrew Windows Cluster 2012 in a one slide diagram
G M
 
Mashup your life with Yahoo Pipes
Cristiano Betta
 
betterCode() Go: Einstieg in Go, Standard-Library und Ökosystem
Jan Stamer
 
Unix Programming with Perl
Kazuho Oku
 

Viewers also liked (10)

PPTX
Current Trends And Technologies Ch-13 (E.M)
MohsinHusenManasiya
 
PPTX
Advanced Scripting (Ch-8) English Medium Std-11
MohsinHusenManasiya
 
PPTX
Advanced Scripting (Ch-8) Gujarati Medium Std-11
MohsinHusenManasiya
 
PPT
Vim Editor And Basic Scripting Gujarati Medium (Ch-7)
MohsinHusenManasiya
 
PPTX
Vim Editor And Basic Scripting (Ch-7)
MohsinHusenManasiya
 
PDF
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
SlideShare
 
PDF
How to Make Awesome SlideShares: Tips & Tricks
SlideShare
 
PDF
Introduction to SlideShare for Businesses
SlideShare
 
PDF
Lead Generation on SlideShare: A How-to Guide
SlideShare
 
PDF
Getting Started With SlideShare
SlideShare
 
Current Trends And Technologies Ch-13 (E.M)
MohsinHusenManasiya
 
Advanced Scripting (Ch-8) English Medium Std-11
MohsinHusenManasiya
 
Advanced Scripting (Ch-8) Gujarati Medium Std-11
MohsinHusenManasiya
 
Vim Editor And Basic Scripting Gujarati Medium (Ch-7)
MohsinHusenManasiya
 
Vim Editor And Basic Scripting (Ch-7)
MohsinHusenManasiya
 
A Guide to SlideShare Analytics - Excerpts from Hubspot's Step by Step Guide ...
SlideShare
 
How to Make Awesome SlideShares: Tips & Tricks
SlideShare
 
Introduction to SlideShare for Businesses
SlideShare
 
Lead Generation on SlideShare: A How-to Guide
SlideShare
 
Getting Started With SlideShare
SlideShare
 
Ad

Similar to Advanced Scripting - 2 (Ch-8) (20)

PPTX
Scripting ppt
anamichintu
 
PDF
Osp2.pdf
ErPawanKumar3
 
PPTX
Unix Shell Programming subject shell scripting ppt
Radhika Ajadka
 
PPTX
Repetition Structures
primeteacher32
 
PDF
OS.pdf
ErPawanKumar3
 
PPTX
Licão 12 decision loops - statement iteration
Acácio Oliveira
 
PPTX
Case, Loop & Command line args un Unix
Vpmv
 
PDF
Slides
abhishekvirmani
 
PPTX
Licão 13 functions
Acácio Oliveira
 
PPTX
Shell Programming Language in Operating System .pptx
SherinRappai
 
PPT
Advanced linux chapter ix-shell script
Eliezer Moraes
 
PDF
Fundamental of Shell Programming
Rahul Hada
 
PPT
Shell programming
Moayad Moawiah
 
PPT
Unix And Shell Scripting
Jaibeer Malik
 
PPT
Unix
nazeer pasha
 
PPTX
Unix shell scripts
Prakash Lambha
 
PPS
UNIX - Class3 - Programming Constructs
Nihar Ranjan Paital
 
PPT
Bash Programming
Kiplangat Chelule
 
PPT
ShellAdvanced shell scripting programm.ppt
ubaidullah75790
 
PPTX
SHELL PROGRAMMING.pptx
Technicaltamila2
 
Scripting ppt
anamichintu
 
Osp2.pdf
ErPawanKumar3
 
Unix Shell Programming subject shell scripting ppt
Radhika Ajadka
 
Repetition Structures
primeteacher32
 
Licão 12 decision loops - statement iteration
Acácio Oliveira
 
Case, Loop & Command line args un Unix
Vpmv
 
Licão 13 functions
Acácio Oliveira
 
Shell Programming Language in Operating System .pptx
SherinRappai
 
Advanced linux chapter ix-shell script
Eliezer Moraes
 
Fundamental of Shell Programming
Rahul Hada
 
Shell programming
Moayad Moawiah
 
Unix And Shell Scripting
Jaibeer Malik
 
Unix shell scripts
Prakash Lambha
 
UNIX - Class3 - Programming Constructs
Nihar Ranjan Paital
 
Bash Programming
Kiplangat Chelule
 
ShellAdvanced shell scripting programm.ppt
ubaidullah75790
 
SHELL PROGRAMMING.pptx
Technicaltamila2
 
Ad

More from MohsinHusenManasiya (20)

PPT
Ch - 01 [Eng-11] Chapter -1
MohsinHusenManasiya
 
PPTX
Storage unit
MohsinHusenManasiya
 
PPTX
Satelite
MohsinHusenManasiya
 
PPTX
QR CODE
MohsinHusenManasiya
 
PPTX
Qr codes
MohsinHusenManasiya
 
PPTX
Teamviewr
MohsinHusenManasiya
 
PPTX
Malware
MohsinHusenManasiya
 
PPSX
Network
MohsinHusenManasiya
 
PPTX
Mobile processor
MohsinHusenManasiya
 
PPTX
Lasik eye surgery
MohsinHusenManasiya
 
PPTX
Internet vs intranet vs extranet
MohsinHusenManasiya
 
PPTX
Ingestible robots
MohsinHusenManasiya
 
PPTX
I3 vs i5 vs i7
MohsinHusenManasiya
 
PPTX
How does wireless inductive charging work
MohsinHusenManasiya
 
Ch - 01 [Eng-11] Chapter -1
MohsinHusenManasiya
 
Storage unit
MohsinHusenManasiya
 
Mobile processor
MohsinHusenManasiya
 
Lasik eye surgery
MohsinHusenManasiya
 
Internet vs intranet vs extranet
MohsinHusenManasiya
 
Ingestible robots
MohsinHusenManasiya
 
I3 vs i5 vs i7
MohsinHusenManasiya
 
How does wireless inductive charging work
MohsinHusenManasiya
 

Recently uploaded (20)

PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
PDF
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PDF
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
How to Manage Large Scrollbar in Odoo 18 POS
Celine George
 
ARAL_Orientation_Day-2-Sessions_ARAL-Readung ARAL-Mathematics ARAL-Sciencev2.pdf
JoelVilloso1
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Lesson 2 - WATER,pH, BUFFERS, AND ACID-BASE.pdf
marvinnbustamante1
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
A PPT on Alfred Lord Tennyson's Ulysses.
Beena E S
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Women's Health: Essential Tips for Every Stage.pdf
Iftikhar Ahmed
 
community health nursing question paper 2.pdf
Prince kumar
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 - GLOBAL SUCCESS - CẢ NĂM - NĂM 2024 (VOCABULARY, ...
Nguyen Thanh Tu Collection
 

Advanced Scripting - 2 (Ch-8)

  • 2. 2 What is Handling Repetition ? Handling Repetition is control structure also known as looping control structure,Handling Repetition is control structure also known as looping control structure, is a type of control structure in programming languages that is used to simplify repetitive oris a type of control structure in programming languages that is used to simplify repetitive or recursive tasks operation.recursive tasks operation.
  • 3. Delete zero sized files in system.Delete zero sized files in system. 3 Code for write a script to delete zero sized files from a given directory (and all its subdirectories) in Unix / Linux / Ubuntu Code for write a script to delete zero sized files from a given directory (and all its subdirectories) in Unix / Linux / Ubuntu
  • 4. 4
  • 5. 5 Script 19 Handling Repetition is control structure also known as looping control structure,Handling Repetition is control structure also known as looping control structure, is a type of control structure in programming languages that is used to simplify repetitive oris a type of control structure in programming languages that is used to simplify repetitive or recursive tasks operation.recursive tasks operation.
  • 6. 6 Repetitive tasks 1.1. The for loopThe for loop 2.2. The while loopThe while loop 3.3. The until loopThe until loop
  • 7. 7 The for loopThe for loop The for loop is the first of the three shell looping constructs. This loop allows for specification of a list of values. A list of commands is executed for each value in the list.
  • 8. 8 for loop Syntaxfor loop Syntax
  • 9. 9 for loop Examplefor loop Example $ cat for1.sh i=1 for day in Mon Tue Wed Thu Fri do echo "Weekday $((i++)) : $day" done $ ./for1.sh Weekday 1 : Mon Weekday 2 : Tue Weekday 3 : Wed Weekday 4 : Thu Weekday 5 : Fri
  • 10. 10 The while loopThe while loop The while construct allows for repetitive execution of a list of commands, as long as the command controlling the while loop executes successfully (exit status of zero) The while construct allows for repetitive execution of a list of commands, as long as the command controlling the while loop executes successfully (exit status of zero)
  • 11. 11 The while loopThe while loop
  • 13. 13 while loop Examplewhile loop Example a=0 while [ $a -lt 10 ] do echo $a a=`expr $a + 1` done
  • 14. 14 The until loopThe until loop
  • 15. 15 until loop Syntaxuntil loop Syntax until <TEST-COMMAND>; do CONSEQUENT - COMMANDS; done
  • 16. 16 until loop Exampleuntil loop Example until [ $DISKFUL -ge "90" ]; do DATE=`date +%Y%m%d` HOUR=`date +%H` mkdir $WEBDIR/"$DATE" while [ $HOUR -ne "00" ]; do DESTDIR=$WEBDIR/"$DATE"/"$HOUR" mkdir "$DESTDIR" mv $PICDIR/*.jpg "$DESTDIR"/ sleep 3600 HOUR=`date +%H` done
  • 18. 18 What is Function ? A function is a subroutine, a code block that implements a set of operations, a "black box" that performs a specified task. Wherever there is repetitive code, when a task repeats with only slight variations in procedure, then consider using a function.
  • 19. 19 Syntax of Function ? function function_name { command... } or function_name () { command... }
  • 22. 22
  • 23. 23
  • 24. 24
  • 25. 25
  • 26. 26
  • 27. 27
  • 28. 28
  • 29. 29
  • 30. 30
  • 31. 31
  • 32. 32