Linux until and while
Updated: 05/04/2019 by Computer Hope
On Unix-like operating systems, until and while are functions of the shell that define a block of code, and a conditional statement.
If while is used, the block loops as long as the condition is true. When the condition is false, the loop terminates.
If until is used, the block loops as long as the condition is false. When the condition is true, the loop terminates.
This page covers the bash built-in versions of until and while.
Syntax
while [ conditions ] ; do actions ; done
until [ conditions ] ; do actions ; done
Examples
filename=anything while [ $filename ] do echo "file?" read filename # read from terminal find . -name $filename -print done
User is repeated prompted for a name of a file to be located, until the user chooses to finish execution.
Related commands
break — Break out of a while, for, foreach, or until loop.
csh — The C shell command interpreter.
ksh — The Korn shell command interpreter.
sh — The Bourne shell command interpreter.