Shell Conditionals

In addition to the built-ins listed in Tables 3.6 and 3.7, the Bourne shell also contains some simple conditionals. A conditional command makes a choice depending on the outcome of a condition. Examples of simple conditionals are && and ||, which I will discuss along with the if and case conditionals in this section.

&& and ||

The simplest conditional in the Bourne shell is the double ampersand (&&). When two commands are separated by a double ampersand, the second command executes only if the first command returns a zero exit status (an indication of successful completion). The following is an example:

ls -ld /usr/bin > /dev/null && echo "Directory Found" 

If the directory /usr/bin exists, the message Directory ...

Get Inside Solaris™ 9 now with the O’Reilly learning platform.

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