loop statment in bash or shell script

Loop statement in bash or shell script

Loop statement in bash or shell script

loop in bash, if ever we want to do some task repeatedly then we use loop statement in bash script.

We have following loop in bash script

The while loop
The for loop
The until loop

syntax

while [ Check for condition ] do
Statements or commands
done

for value in parameter1 parameter2 parameter3
do
Statements or commands
done

#!/bin/bash

for i in 1 2 3 4 5
do
echo "$i"
done
#!/bin/bash

for Cources in ccna ccnp bashScript
do
echo $Cources 

done

 

Its always required semicolon while we use do keywords  on the same line with while keywords
while [ condition ] ; do

#!/bin/bash
Num=0
while [ $Num−lt 10 ]; do
echo The counter is $Num
let Num=Num+1
done

Until Example

#!/bin/bash
Num=20
until [ $Num−lt 10 ]; do

echo Num $Num
let Num−=1
done

You May Also Enjoy Reading This …

Leave a Reply

Your email address will not be published. Required fields are marked *