18.2. Control structures
With very few exceptions, nearly all scripts have some type of flow control in them. What is flow control? Well, suppose you had a script containing a few commands like this:
#!/bin/sh # make a directory mkdir /home/dave/mydocs # copy all doc files cp *.docs /home/dave/docs # delete all doc files rm *.docs
The above is a script; it does a job – what’s the problem? The problem is what happens if the directory cannot be created. What happens if the directory can be created but fails when the copy tries to copy the files? What if you need to cp different files from different directories. We need to make informed decisions before the command takes place or more likely on the outcome of the last command. The shell comes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access