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
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.
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)
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...
}