Chapter 3. Conditions Attached
Now you can make your scripts more interactive using the read
command, and you know how to read parameters and options to lighten your inputs.
We can say that we are now into the fine print of the script. These are the details that are written into our scripts using conditions to test if a statement should run or not. We are now ready to add some intelligence into our scripts, so our scripts become more robust, easier to use, and more reliable. Conditional statements can be written with simple command-line lists of AND
or OR
commands together, or, more often, within traditional if
statements.
In this chapter, we will cover the following topics:
- Simple decision paths using command-line lists
- Verifying user input with lists
- Using the test shell built-in
- Creating conditional statements using
if
- Extending
if
withelse
- Using the
test
command with theif
command - More conditions with
elif
- Using case statements
- Recipe-frontend with
grep