Concepts:
The "boxes" that represent the
commands in the script file are oddly shaped if you have never seen
them before, but the meaning of each shape is
explained in the graphic on page 342. The text shows twelve
separate shapes for various kinds of actions that the script might
take, and
arrows to show the flow from one object to another. The shapes you use
in a flow chart provide meaning that would otherwise have to be
explained by the text that you write in those shapes. There are more
standard shapes that you might use, some of which are explained on this web page from the Lucid Chart company. To choose the
right shape, you need to know what they stand for, and what you want to
do in each command in your script. All of the symbols in the example
flowchart on page 341 are available to Baker students in Lucid Charts.
To use Lucid Charts, sign in to MyBaker, then open BakerMail, as shown
in the image on the right. Click it to open the
Apps
menu, then find and click the word More.
There is another ellipse around it in the image on the on the left. You
will see a few more icons. Find and click the one for Lucid Chart. It
is orange, and is shown in the image on the right. Once you have Lucid Chart open, you can start a new document,
tell it you want to create a flowchart, and start planning a program or
a shell script. Obviously, you can also use this tool to document an existing program or script. If you did not have a drawing tool, or an understanding of the shapes in a flowchart, you might use pseudocode as your planning/documentation method. Pseudocode is a generic name for describing
what a program does, step by step, in terms the end user might
understand. Pseudocode can be used to plan the features of a program
even if you do not yet know what language will be used to create that
program. In the example on page 343, the text shows us that the
features of the example program can be described briefly, in less space
than the real script requires, which is typical. Note that the person
who wrote the pseudocode assumes that the person reading the pseudocode
will understand an if structure and understand that veg_name is a variable.
Even though this method is meant to be written plainly enough for end
users to grasp, it is really meant to be a planning tool for one or
more programmers, so some assumptions like the ones I mentioned are
allowed. We will move on to page 344. On that page, the text tells us
something that should worry you. If you want to invoke a particular
shell when you run a script, you can use something that is called by several
names: hashbang, shebang, sha-bang, and others. Its
purpose is to invoke a new shell for your program. Its syntax follows
this model: There are several items following this section that don't have a lot of value. Let's move on to page 348, and examine the test command. The text shows us that the command has several switches that can be used to evaluate the existence of files and directories. It can be used to check the permissions on files as well. The next several pages in this chapter demonstrate other switches that can run other kinds of tests. In the example on pages 349 and 350, the text compares a Boolean test of equality in the entry condition of a do loop to the same condition being evaluated with the test command. Note that the syntax for the test command does not require square brackets, or quotation marks around the variable being evaluated. In the discussion of the test command on page 350, the chapter introduces the idea of an exit status. In a way, it is like a temporary variable that you can access, providing you do it quickly. The example goes like this: value=17 The following pages show how to use the test command to compare strings, as well as measuring their length, and how to conduct tests on files and directories. On page 353, the text tells us that we can combine the tests we run with the equivalent of Boolean AND, OR, and NOT operators. If you have never done this, first review the option switches on page 353 that stand for those three concepts:
Now consider the possibilities that the text brings up:
|