Summary
Structured commands allow you to alter the normal flow of shell script execution. The most basic structured command is the if-then
statement. This statement provides a command evaluation and performs other commands based on the evaluated command's output.
You can expand the if-then
statement to include a set of commands the bash shell executes if the specified command fails as well. The if-then-else
statement executes commands only if the command being evaluated returns a non-zero exit status code.
You can also link if-then-else
statements together, using the elif
statement. The elif
is equivalent to using an else if
statement, providing for additional checking of whether the original command that was evaluated failed.
In most scripts, instead of evaluating a command, you'll want to evaluate a condition, such as a numeric value, the contents of a string, or the status of a file or directory. The test
command provides an easy way for you to evaluate all these conditions...