Design Scripts  «Prev  Next»
Lesson 3Diagramming script flow
ObjectiveUse a flow diagram to help plan a script.

Diagramming Script Flow

Once you have a clear objective and feel confident that your project is appropriate to a shell script, the next step is to outline how the script will proceed to accomplish its objective.

How to Outline a Script

People who write programs frequently use formal methods for testing on paper how a program will work, such as relying on rules and flowchart symbols. I find that writing a series of statements with a few arrows generally does the trick. This is especially true for shell scripts, which by and large are not highly complex in structure. A diagram or a list of statements that captures the flow of control and actions occurring within a script does not rely on using programming words. Instead, it helps you see how you can accomplish the script objective.
If we use the objective presented in the previous lesson, our script outline might look like this (the information here is specific to the example):

Script outline
Script outline

This list is simple, it does not even use arrows.

The benefits of outlining your script

Diagramming or writing out in plain English what you want the script to do can help in several ways:
  1. It lets you see what commands will be used, so that you can start determining how to use them in the script.
  2. It identifies possible errors in logic, based on where each statement in the script fits in.
  3. It helps you create “clean code” in which all variables are initialized at the beginning of the script and all files are closed at the end of the script, because everything that is needed is identified before starting to code.
  4. It points out places where you can protect against user errors that might cause the script to malfunction.

The next lesson uses some of the information provided by a script outline to determine what tests the script should include.

Diagramming Script Flow - Exercise

Click the Exercise link to practice arranging the steps in a typical script outline.
Diagramming Script Flow - Exercise