If Test
To find out the truth, you must ask questions. The if test provides a means for the script to query a variable, compare strings, check a loop counter, find out whether a command completed successfully, and perform similar activities.
Basic if-test syntax is as follows:
if command then command(s) fi
Cute, huh? The logic of the if test is bracketed by the words if and fi, which is “if” spelled backwards. You will see this same cuteness one other time in this chapter (case/esac). The syntax means that if the command is true, then do the command or commands appearing between the then and the fi. But how does a command become true or false?
As a command completes, it reports its exit status to the shell. This status is held in a special ...
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.