Testing for Conditions

When writing scripts, you frequently want to test for conditions. The simplest test is to determine whether a condition is true or false. If the expression is true, execute any subsequent commands (shown indented in Table 90); if not, continue with the script. Table 90 shows the syntax for conditional tests.

Table 90. Conditional Test Syntax
Bourne and Korn Shells C Shell
if command

then

  commands

elif command
										  commands

else

  commands

fi
if (cond) then

  commands

else if (cond) then

  commands

else

  commands

endif

if-then-else-elif

For the Bourne and Korn shells, use the if-then-else-elif-fi syntax to test for conditions. You can follow the if statement with the test command and its argument(s) to test for conditions. ...

Get Solaris™ 8 Advanced System Administrator's Guide, Third Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.