done
Marks end of loop or conditional block
TLDR
View documentation for the for keyword
View documentation for the while keyword
View documentation for the select keyword
View documentation for the until keyword
SYNOPSIS
Since done is a keyword and not a standalone command, its "synopsis" describes its usage within shell loop structures:
for VARIABLE in LIST; do
commands
done
while CONDITION; do
commands
done
until CONDITION; do
commands
done
select VARIABLE in LIST; do
commands
done
PARAMETERS
N/A
The 'done' keyword does not accept parameters or options; it solely serves as a structural delimiter in shell loops.
DESCRIPTION
done is not a standalone executable command on Linux systems. Instead, it is a fundamental keyword used in various shell scripting constructs, primarily to mark the end of a do...done block for loops. It signifies the conclusion of the command list that is executed repeatedly within for, while, until, and select loops. It plays a crucial role in defining the scope of operations that are part of an iterative process in shell scripts. Without the done keyword, shell parsers would not be able to correctly identify the boundaries of loop bodies, leading to syntax errors. Its purpose is purely structural, defining control flow rather than performing an action itself.
CAVEATS
done is a keyword in shell scripting, not an executable command. Attempting to run done directly in a terminal will result in a "command not found" error. Its functionality is strictly tied to shell loop constructs (for, while, until, select), where it marks the end of the block of commands to be executed. It should not be confused with the concept of job completion or a "task done" utility, unless such a utility has been specifically aliased or scripted by a user.
USAGE EXAMPLE
Here is a simple example demonstrating the use of the done keyword within a for loop:
#!/bin/bash
for i in 1 2 3 4 5; do
echo "Current number: $i"
done
echo "Loop finished."
This script will iterate through the numbers 1 to 5, printing the current number in each iteration, and then print "Loop finished." after the loop completes.
HISTORY
The done keyword's history is inextricably linked to the evolution of Unix shells. It originated with the Bourne Shell (sh), introduced in 1977, as a fundamental component of its control flow syntax for loops. Its purpose, along with do, was to clearly delineate the block of commands to be repeatedly executed. This syntax was then inherited and maintained by subsequent shell implementations, including the Korn Shell (ksh), C Shell (csh), and notably the GNU Bourne-Again Shell (bash), which is the default shell on most Linux distributions today. Its consistent presence across various shells highlights its fundamental and stable role in shell scripting for defining iterative operations.