Javatpoint Logo
Javatpoint Logo

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





Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA