Chapter 8. Decisions, Decisions

This chapter introduces a statement that is present in almost all programming languages: if. It enables you to test a condition and then change the flow of program execution based on the result of the test.

The general format of the if command is

if commandt
then
        command
        command
     ...
fi

where commandt is executed and its exit status is tested. If the exit status is zero, the commands that follow between the then and the fi are executed; otherwise, they are skipped.

Exit Status

Whenever any program completes execution under the Unix system, it returns an exit ...

Get Unix Shell Programming, Third Edition now with O’Reilly online learning.

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