Home » While Loop Shell Scripting

While Loop Shell Scripting

by Online Tutorials Library

Shell Scripting while loop

Linux scripting while loop is similar to C language while loop. There is a condition in while. And commands are executed till the condition is valid. Once condition becomes false, loop terminates.

Syntax:

Syntax of while loop is shown in the snapshot below,

Linux Shell Scripting While loop 1

Example:

We have shown the example of printing number in reverse order.

Shell Scripting While loop 2

Output is displayed in the below snapshot,

Shell Scripting While loop 3


while infinite loop:

Infinite loop is also called endless loop. It is made with while true (it means condition will always be true) or while : (it means an empty expression), where colon (:) is equivalent to no operation.

Shell Scripting While loop 4

Look at the above snapshot, this script includes while truesyntax.

Linux Shell Scripting While loop 5

Look at the above snapshot, this script includes while: syntax.

Both of them display the same output.

Next TopicUntil loop

You may also like