if

Official Description

Executes the list following if and, if it returns a 0 (zero) exit status, executes the list following the first then.

Syntax

if list ;then list [elif list ;then list] ... [;else list] ;fi

Options

None

Oddities

At least one command must appear between the then and the fi (it can be a : if you want it to do nothing).

Place numeric tests in (( )); place string tests in [[ ]].

Example

$ x=12
$
$ if (( x == 12 ))
> then
> print "equal"
> else
> print "not equal"
> fi
equal
$
				

Get Korn Shell Programming by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.