If/Then
Almost every programming language has an if/then/else construct, and the shell is no exception. The syntax uses square brackets to perform a test, and the then and fi statements are required, acting just like the { and } curly brackets in C and some other languages.
if [ condition ] then statement(s) fi
Other than the line break after the word then, all these line breaks are required or can be replaced with semicolons. The spaces around the [ and ] symbols are also required, so this can be reduced at best to:
if [ condition ];then statement(s);fi
It is quite common to use the semicolon to put the then on the same line as the if. The technique of reversing a word to mean its opposite — for example, using fi to end an if statement — comes up again later in this chapter, where case statements are ended with an esac. Similarly, as you see in Chapter 12, the reverse of cat is tac.
The Unix, Linux, and Free Software traditions have a lot of (self-consciously) awful puns. In addition to the wordplay behind GNU and HURD mentioned in Chapter 1, Perlmongers attend Yet Another Perl Conference (YAPC), SuSE employs Yet Another Software Tool (YaST), and abcde is A Better CD Encoder. The Latin American GNU National User Groups are called GNU^2 (Grupos Nacionales de Usarios GNU); the list is virtually endless.
You can make this code more useful by having a section of code that ...