Lets see about some more loop statements which can be used in unix shell scripting
while: while followed by condition then set of statements to be executed do,done act as flower braces
Syntax: while [condition/statement]
do
statement 1
statement 2
:
:
statement n
done
eg:
#!/bin/sh
a=0
while [ $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
Output will be as follows
0
1
2
3
4
5
6
7
8
9
Until: This command functionality is viceversa of while command. In while the loops continues to execute when condition is true , but in until the loops continues to execute until the condition is false.
Syntax: until [condition/statement]
do
statement 1
statement 2
:
:
statement n
done
eg:
#!/bin/sh
a=0
until [ ! $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
output will be as follows
0
1
2
3
4
5
6
7
8
9
while: while followed by condition then set of statements to be executed do,done act as flower braces
Syntax: while [condition/statement]
do
statement 1
statement 2
:
:
statement n
done
eg:
#!/bin/sh
a=0
while [ $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
Output will be as follows
0
1
2
3
4
5
6
7
8
9
Until: This command functionality is viceversa of while command. In while the loops continues to execute when condition is true , but in until the loops continues to execute until the condition is false.
Syntax: until [condition/statement]
do
statement 1
statement 2
:
:
statement n
done
eg:
#!/bin/sh
a=0
until [ ! $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done
output will be as follows
0
1
2
3
4
5
6
7
8
9
Hope this helps you in understanding unix loop commands
Comments
Post a Comment