Advanced if-then-else
This chapter is dedicated to everything to do with conditional testing and scripting loops, which are two concepts that are often intertwined. We have already seen the if-then-else
loop in Chapter 9, Error Checking and Handling, which focused on error checking and handling. We'll present a small recap of the things we've described regarding if-then-else
, before moving on to advanced concepts.
A recap on if-then-elseÂ
If-then-else
logic does almost exactly what the name implies: ifsomething-is-the-case, thendo-something or elsedo-something-else. In practice, this could be ifthe disk is full, thendelete some files or elsereport that the disk space looks great. In a script, this could look something like this:
reader@ubuntu:~/scripts/chapter_09$ cat if-then-else-proper.sh #!/bin/bash ##################################### # Author: Sebastiaan Tammer # Version: v1.0.0 # Date: 2018-09-30 # Description: Use the if-then-else construct, now properly. # Usage: ./if-then-else-proper...