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;] fiReturn 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