/ factorpad.com / tech / linux-essentials / until-command.html
An ad-free and cookie-free website.
Intermediate
Learn to create a program loop in a bash shell script at the Linux command line.
Videos can also be accessed from the Linux Essentials Playlist on YouTube.
Linux bash until loop with Examples (3:40)
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).
-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.
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.
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
.
Very good (remember we will return to our final script in the next tutorial).
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).
For an overview of the 100 videos, the 8 quizzes, a cheat sheet, the categories and a Q&A section, visit:
If you learned something here, please consider giving back and helping with the mission of offering ad-free learning of important technical skills.
for
statement,
hit Back.fold
command. Click Next./ factorpad.com / tech / linux-essentials / until-command.html
A newly-updated free resource. Connect and refer a friend today.