Build a Better Process

Linux bash until Loop with Examples

Linux until allows you to create a program loop within a shell script (until is techically a bash keyword, not a command).
  1. Purpose - Learn what until is for and how to find help.
  2. Options - Review a few common options and arguments.
  3. Examples - Walk through code examples with until.
  4. A tip - Finish off with one more insight.
face pic by Paul Alan Davis, CFA
Updated: February 24, 2021
In this tutorial on Linux until, 99 of 100, below find a 3-4 minute introductory video, a text-based tutorial and all of the code examples from the video.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / until-command.html

An ad-free and cookie-free website.

Examples of the Linux until command (keyword)


Learn to create a program loop in a bash shell script at the Linux command line.

Video Tutorial

Videos can also be accessed from the Linux Essentials Playlist on YouTube.

Linux bash until loop with Examples (3:40)

Video Script

The Command and Why You Need It

Our ninety-ninth word, or command (keyword) to memorize is until from our category Workflow.

until allows you to create a program loop (like in a bash shell script).

Common Linux until Options
-options description
None for Linux until

Recall from videos (tutorials) #96 and #98 on while and for we explored keywords used to create loops, and now we'll see a third example.

Before we start, it helps to think of commands as mini programs and most follow this structure: command -option(s) argument(s).

The until command (keyword) has no traditional options and no arguments as it is technically a keyword, and it too uses do and done syntax, like we've seen before.

Unlike most commands, help is not available with double-dash --help, as until is a shell built-in covered in the bash manual page.

So why is until an important command (keyword)? Well, until is very similar to while, and it gives you another option for simplifying loop logic. And now you know how to do that.


Okay, the best way to embed this in your memory is by typing in your own terminal window.

Find this on your Mac using a program called Terminal. On Linux use Terminal or Konsole, and currently Microsoft is adding this functionality to Windows.

Here we go. Let's review the 3 keywords in this group.

$ type until; type do; type done until is a shell keyword do is a shell keyword done is a shell keyword

All, as you can see, are keywords.

Next, let's create a loop using the same while statement at the command line as we did in video (tutorial) #96. Start by setting the count equals to 1.

Then the logic with while was: while count is less than or equal to 8, print the count, then add one to the count, and head back up until the exit code from the while is not true, thus it repeats.

$ count=1 $ while [ $count -le 8 ]; do echo $count; count=$((count+1)); done 1 2 3 4 5 6 7 8

And then last, let's compare. We will get that same result with until. Except here, the exit status is false until it gets to greater than 8, so false 8 times, then the count is above 8 and it breaks out of the loop and hits the done.

$ count=1 $ until [ $count -gt 8 ]; do echo $count; count=$((count+1)); done 1 2 3 4 5 6 7 8

Very good (remember we will return to our final script in the next tutorial).

A Final Tip

Okay now you know how to use until. And you know the syntax for commands, options and arguments.

One last tip about the until command (keyword). So when do you use until versus while? It can be personal preference, but with experience one or the other will allow you to simplify the code, which really is the goal.

Okay, thanks for visiting today. I hope this was a helpful introduction to the until command (keyword).

Learn More About The Series

For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:

What's Next?

If you learned something here, please consider giving back and helping with the mission of offering ad-free learning of important technical skills.

Outline Back Tip Next

/ factorpad.com / tech / linux-essentials / until-command.html

linux until loop
bash until
bash loop
bash programming
until bash
bash script
until loop
do until
do until loop
loop until
do loop until
shell until loop
shell until
linux until examples
until loop examples
linux until tutorial
shell scripting
do until examples
linux until keyword
linux until statement
bash until statement
linux program iterator
bash script

A newly-updated free resource. Connect and refer a friend today.