Control Flow Constructs

Use these structures to build reusable scripts with decisions, loops, and user-defined command returns.

If Statements

if <condition> then
    <statements>
[elif <condition> then
    <statements>]...
[else
    <statements>]
fi

While Loops

while <condition> do
    <statements>
done

For Loops

for <var> in <val1> <val2> ... do
    <statements>
done

Break & Continue

Use break to exit loops and continue to skip to the next iteration.

Return

Use return <expression> to exit a user-defined command with a status.