Chapter 7. Conditional statements

Table of Contents
7.1. Introduction to if
7.1.1. General
7.1.2. Simple applications of if
7.2. More advanced if usage
7.2.1. if/then/else constructs
7.2.2. if/then/elif/else constructs
7.2.3. Nested if statements
7.2.4. Boolean operations
7.2.5. Using the exit statement and if
7.3. Using case statements
7.3.1. Simplified conditions
7.3.2. Initscript example
7.4. Summary
7.5. Exercises

In this chapter we will discuss the use of conditionals in Bash scripts. This includes the following topics:

  • The if statement

  • Using the exit status of a command

  • Comparing and testing input and files

  • if/then/else constructs

  • if/then/elif/else constructs

  • Using and testing the positional parameters

  • Nested if statements

  • Boolean expressions

  • Using case statements