Skip to Content
Learning Linux Shell Scripting
book

Learning Linux Shell Scripting

by Ganesh Sanjiv Naik
December 2015
Beginner
306 pages
5h 2m
English
Packt Publishing
Content preview from Learning Linux Shell Scripting

Using until

The until command is similar to the while command. The given statements in the loop are executed as long as they evaluate the condition as true. As soon as the condition becomes false, then the loop is exited.

The syntax is as follows:

until command
do
    command(s)
done

In the following script until_01.sh, we are printing numbers 0-9 on screen. When the value of variable x becomes 10, then the until loop stops executing:

#!/bin/bash
x=0
until [ $x -eq 10 ]
do
  echo $x
  x=`expr $x + 1`
done

Let's test the program:

$ chmod +x until_01.sh
$ ./until_01.sh

The following will be the output after executing the preceding commands:

0
1
2
3
4
5
6
7
8
9

In the following script until_02.sh, we ask the user to input text. We are printing entered text on ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning Linux Shell Scripting - Second Edition

Learning Linux Shell Scripting - Second Edition

Ganesh Sanjiv Naik

Publisher Resources

ISBN: 9781785286216