Bash until Loop and Bash until Loop Example

Bash until Loop and Bash until Loop Example

This tutorial explains the basics of the until loop in Bash. The until loop is used to execute a given set of commands as long as the given condition evaluates to false.

Loops are one of the fundamental concepts of programming languages. Loops are handy when you want to run a series of commands over and over again until a specific condition is met.

In scripting languages such as Bash, loops are useful for automating repetitive tasks. There are 3 basic loop constructs in Bash scripting, [for](https://linuxize.com/post/bash-for-loop/) loop[while](https://linuxize.com/post/bash-while-loop/) loop, and until loop.

This tutorial explains the basics of the until loop in Bash.

Bash until Loop

The until loop is used to execute a given set of commands as long as the given condition evaluates to false.

The Bash until loop takes the following form:

until [CONDITION]
do
  [COMMANDS]
done

Copy

The condition is evaluated before executing the commands. If the condition evaluates to false, commands are executed. Otherwise, if the condition evaluates to true the loop will be terminated and the program control will be passed to the command that follows.

In the example below, on each iteration the loop prints the current value of the variablecounterandincrements the variableby one.#!/bin/bash

counter=0

until [ $counter -gt 5 ]
do
  echo Counter: $counter
  ((counter++))
done

Copy

The loop iterates as long as the counter variable has a value greater than four. The script will produce the following output:

Counter: 0
Counter: 1
Counter: 2
Counter: 3
Counter: 4
Counter: 5

Use the [break](https://linuxize.com/post/bash-break-continue/) and [continue](https://linuxize.com/post/bash-break-continue/) statements to control the loop execution.

bash loop bash until loop

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Bash For Loop,The Standard Bash for Loop

In this tutorial, we will cover the basics of for loops in Bash. We will also show you how to use the break and continue statements to alter the flow of a loop.

Bash while Loop and Infinite while Loop

Loops are one of the fundamental concepts of programming languages. This tutorial covers the basics of while loops in Bash.

How to Use If-Else Statements and Loops in R – Dataquest

Learn to use if-else statements, for loops, and while loops to build complex conditional programs in R, a valuable skill for aspiring data scientists.

For loop in C++ Program | C++ For Loop Example

For loop in C++ Program | C++ For Loop Example.

Bash Select (Make Menus) and Bash select Example

In this tutorial, we will cover the basics of the select construct in Bash. The select construct generates a menu from a list of items. It has almost the same syntax as for loop.If the user enters a number that corresponds to the number of one of the displayed items, then the value of [ITEM] is set to that item. The value of the selected item is stored in the variable REPLY. Otherwise, if the user input is empty, the prompt and the menu list are displayed again.