keyword

Bash if conditional

Selects commands by condition exit status. Optional branches are shown in brackets, not literal syntax. Zero selects the branch.

Formal Syntax & Structure

bash syntaxbash
if command; then commands; [elif command; then commands;] [else commands;] fi

Return Value

behavior

Selects commands by condition exit status. Optional branches are shown in brackets, not literal syntax. Zero selects the branch.

Working Example

Example Snippetbash
if false; then  printf '%s\n' firstelif true; then  printf '%s\n' secondelse  printf '%s\n' fallbackfi
Bash Reference