Receive all updates via Facebook. Just Click the Like Button Below

While Loop

A while loop is executed as long as a given condition is true.
Here we will learn the use of while loops.

1

While Loop in Linux Shell Scripting

2

Syntax:

 
 while [ condition ]
           do
                { code to execute }
                 ....
            done
            

Example: while.sh

 
#!/bin/sh
# Get the value from the user
echo " Enter a value for the variable x:"
read x

while [ $x -le 10 ]
do
echo "The value of x is $x"
x=`expr $x + 1`
done
            

Result:
./while.sh

 
Enter a value for the variable x:
6
The value of x is 6
The value of x is 7
The value of x is 8
The value of x is 9
The value of x is 10
            

In the above example, the value of x is 6.
Each time the loop is executed, the x value is incremented. The loop continues until the value of x is less than 10.
Once the condition is satisfied, the control come out of the loop.

3

Related posts:

Advertise here

picture picture

Follow us

picture

- Tech-Tutorials twitter.com/techcuriosity

Like us

About Techcuriosity

I am Telson, the webmaster of Techcuriosity.com and through this site, I share my knowledge and curiosities in the Tech World.


What We Offer

  • What is ..?
  • How to ..?
  • Difference between ..?
  • How .. works?
  • Get in Touch

    techcuriosity@gmail.com
    UK : +44 77 33 890 678

    picture picture

    Our Partners

  • Website Design Dubai
  • SEO Link Exchange
  • picture

    picture