Syntax

Bash While Loop Syntax

In Bash, while loop: repeats while a condition is true — while [[ $i -lt 5 ]]; do ((i++)) done

Quick Answer

Syntax
while [[ $i -lt 5 ]]; do ((i++)) done
BashSyntax

While Loop

Code example
while [[ $i -lt 5 ]]; do ((i++)) done

Repeats while a condition is true.

Learn More

How to while loop in Bash

  1. Open your Bash file or editor.
  2. Copy the example, then replace its sample names and values for your code.

Bash While Loop Syntax

Use while [[ $i -lt 5 ]]; do ((i++)) done.

Related Syntax References

Frequently asked questions

What is the Bash syntax for while loop?

Use this pattern: while [[ $i -lt 5 ]]; do ((i++)) done

Can I copy this Bash code example?

Yes. Use Copy code and adapt the example to your program.

Is this Bash syntax different on Mac or Windows?

No. The language syntax is the same across operating systems.

Official source · How we verify