Hello everyone ;
I am Teertha Darekar
Welcome back to my day 8 blog of linux Workshop conducted by :-Pranav Jambare sir.
CONTENTS :-
Loops
let's start ;
--> LOOPS
A loop is a powerful programming tool that enables you to execute a set of commands repeatedly.
There are three types of loops in linux .
While loop
Until Loop
For Loop
1 ) While Loop :-
- If the condition remains satisfied the loops runs , if condition raise to false then loop will be terminated .
Syntax :-
while <condition>
do
statement executed if the command is true
done
Example :-
#!/bin/bash
A=0
while [ ${A} -lt 20 ];
do
echo " ${A}"
A=` expr ${A} + 1`
done
2) Until Loop :-
- If the condition remains unsatisfied the loops runs , The loop terminates when the condition becomes true.
Syntax :-
until <condition>
do
statement executed if the command is true
done
Example :-
#!/bin/bash
A=20
until [ ${A} - lt 00 ];
do
echo " ${A}"
A=` expr ${A} - 1`
done
3) For Loop :-
- The for loop operate on lists of items. It repeats a set of commands for every item in a list.
Syntax :-
for var in word1 word2..wordn --(var=variable)
do
statement executed till element end
done
Example :-
#!/bin/bash
for var in Teertha Swar Purva Prashant;
do
echo " my name is ${var}"
done
To print the names from file :-
for name in $(cat/root/name) *name = file name*
do
echo "current name is ${name}"
done
Command Line Argument :-
- Command-line arguments are parameters that are passed to a script while executing them in the bash shell.
$1 $2 $3 -> Arguments passed .
$0 -> Name of the shell program .
$@ -> One by one arguments passed .
$# -> Total number of arguments .
$* -> All arguments together .
$$ -> PID(Process ID) of current shell. (Actually the program PID can be achieve) .
$? -> Status of last command .
$! -> PID of last command.
Thank youu ....