You are on page 1of 4

Unix Shell The while Loop

http://www.tutorialspoint.com/unix/while-loop.htm

!
! Search

Unix for Beginners

Unix - Home
Unix - Getting Started
Unix - File Management
Unix - Directories
Unix - File Permission
Unix - Environment
Unix - Basic Utilities
Unix - Pipes & Filters
Unix - Processes
Unix - Communication
Unix - The vi Editor

"

Unix Shell Programming

Unix - What is Shell?


Unix - Using Variables
Unix - Special Variables
Unix - Using Arrays
Unix - Basic Operators
Unix - Decision Making
Unix - Shell Loops
Unix - Loop Control
Unix - Shell Substitutions

1 de 4

11/5/16 7:07 p.m.

Unix Shell The while Loop

http://www.tutorialspoint.com/unix/while-loop.htm

Unix - Quoting Mechanisms


Unix - IO Redirections
Unix - Shell Functions
Unix - Manpage Help

Advanced Unix

Unix - Regular Expressions


Unix - File System Basics
Unix - User Administration
Unix - System Performance
Unix - System Logging
Unix - Signals and Traps

Unix Useful Resources

Unix - Useful Commands


Unix - Quick Guide
Unix - Builtin Functions
Unix - System Calls
Unix - Commands List
Unix - Useful Resources
Unix - Discussion

Unix Shell - The while Loop


Advertisements

Thank you for helping us measure the


Internet.

Previous Page

Next Page $

The while loop enables you to execute a set of commands repeatedly until some condition
occurs. It is usually used when you need to manipulate the value of a variable repeatedly.

2 de 4

11/5/16 7:07 p.m.

Unix Shell The while Loop

http://www.tutorialspoint.com/unix/while-loop.htm

Syntax
while command
do
Statement(s) to be executed if command is true
done

Here Shell command is evaluated. If the resulting value is true, given statement(s) are
executed. If command is false then no statement would be not executed and program would
jump to the next line after done statement.

Example
Here is a simple example that uses the while loop to display the numbers zero to nine
#!/bin/sh
a=0
while [ $a -lt 10 ]
do
echo $a
a=`expr $a + 1`
done

This will produce following result


0
1
2
3
4
5
6
7
8
9

Each time this loop executes, the variable a is checked to see whether it has a value that is
less than 10. If the value of a is less than 10, this test condition has an exit status of 0. In
this case, the current value of a is displayed and then a is incremented by 1.

Previous Page

Next Page $
Advertisements

3 de 4

11/5/16 7:07 p.m.

Unix Shell The while Loop

http://www.tutorialspoint.com/unix/while-loop.htm

RECHARGEABLE BATTERIES

alibaba.com

Find Quality Products from Veried Suppliers. Get a Live Quote Now!

Write for us

FAQ's

Helping

Contact

Copyright 2016. All Rights Reserved.


Enter email for newsletter

4 de 4

go

11/5/16 7:07 p.m.

You might also like