O'Reilly logo

Linux and Unix Shell Programming by David Tansley

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required