while loops and until loops

When using the for loop, we iterate through a list; it's either the one that we create or the one that is dynamically generated. Using the while or until loops, we loop based on the fact that the condition becomes either true or false.

A while loop loops while the condition is true and, conversely, an until loop will loop while the condition is false. The following command will count from 10 through to zero, each iteration of the loop printing the variable and then reducing the value by one:

$ COUNT=10
$ while (( COUNT >= 0 )) ; do
echo -e "$COUNT \c"
(( COUNT-- ))
done ; echo  

We can see the output of this command in the following screenshot, thus confirming the countdown to zero:

The use of the \c escape sequence ...

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.