Until loop in Shell

The while loop is perfect for the situation where you want to execute a set of commands while some conditions are true. Sometimes you need to execute a set of commands until a condition is true, then you need to use a until loop .

Syntax in Unix / Linux

 until command do cac lenh duoc thuc thi toi khi command la true done 

Here the command is estimated. If the value is false , the command is executed. If the command is true , then the command will not be executed and the program will jump to the command line after the done command.

For example in Unix / Linux

Here is a simple example that uses a until loop to display numbers from 0 to 9.

 #!/bin/sh a = 0 until [ ! $a - lt 10 ] do echo $a a = `expr $a + 1` done 

It will produce the following result:

 0 1 2 3 4 5 6 7 8 9 

According to Tutorialspoint

Previous article: for loop in Shell

Next article: Select loop in Shell

4 ★ | 1 Vote

May be interested

  • Select loop in ShellPhoto of Select loop in Shell
    the select loop provides an easy way to create a numbered menu from which the user can select. it is useful when you want to ask the user to select one or more items from a list of options.
  • Regular Expression in Unix / LinuxPhoto of Regular Expression in Unix / Linux
    a regular expression is a string that can be used to describe different sequences (arrangement) of characters. regular expression is often used by various unix commands, including ed, sed, awk, grep and micro domains.
  • Basic file system in Unix / LinuxPhoto of Basic file system in Unix / Linux
    a file system is a logical collection of files on a partition or a disk. a partition is an information store and can be combined into a hard disk if desired.
  • User management in Unix / LinuxPhoto of User management in Unix / Linux
    unix supports a concept of group account, which groups a number of accounts logically. each account will be part of any group account. the unix team plays an important role in executing process management and allowing access to files.
  • System performance in Unix / LinuxPhoto of System performance in Unix / Linux
    the purpose of this tutorial is to introduce performance analysis with the tools available for monitoring and managing performance on unix systems, and to provide a general guideline on how to detect and fix performance issues in unix environments.
  • System log in Unix / LinuxPhoto of System log in Unix / Linux
    unix systems have a very powerful and flexible logging system, which gives you the ability to record almost anything you can imagine and then manipulate this log to track the information you require.