Name
if
Synopsis
if
test-cmds
Begin a conditional statement. The possible formats, shown here side by side, are:
iftest-cmds
iftest-cmds
iftest-cmds
then then thencmds1
cmds1
cmds1
fi else eliftest-cmds
cmds2
then ficmds2
... elsecmdsn
fi
Usually, the initial if and any elif lines execute one test or [ ] command (although any series of commands is permitted). When if succeeds (that is, the last of its test-cmds returns 0), cmds1 are performed; otherwise, each succeeding elif or else line is tried.
Get Linux in a Nutshell, Fourth Edition 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.