fi
shell keyword to close conditional blocks
TLDR
End if statement
SYNOPSIS
if condition; then commands; fi
DESCRIPTION
fi is a shell keyword that closes an if conditional block. It's part of the shell's control flow syntax, marking where conditional execution ends.
The if/then/fi structure evaluates conditions and executes code blocks based on exit statuses. Conditions can use test commands, [[ ]], or any command's exit status.
fi must appear for every if, matching them like parentheses.
PARAMETERS
if
Begin conditional block.then
Commands to execute if condition is true.elif
Else-if for additional conditions.else
Commands if no conditions matched.fi
End of if block (if spelled backward).
CAVEATS
Must have matching if. Requires semicolon or newline before fi. Syntax errors from missing fi are common.
HISTORY
fi is part of Bourne shell syntax from the 1970s. The reversed spelling of "if" matches other shell block terminators like esac (case reversed) and done (for/while/until).
